hytos / DTI_PID / ID2PSN / PSN.cs @ 2ada3be8
이력 | 보기 | 이력해설 | 다운로드 (66.9 KB)
1 | 6b9e7a56 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Data; |
||
4 | using System.IO; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Threading.Tasks; |
||
8 | 7881ec8f | gaqhf | using ID2PSN.Properties; |
9 | using System.Text.RegularExpressions; |
||
10 | 5dfc785c | LJIYEON | using System.Windows.Forms; |
11 | 6b9e7a56 | gaqhf | |
12 | namespace ID2PSN |
||
13 | { |
||
14 | public enum PSNType |
||
15 | { |
||
16 | None, |
||
17 | Branch, |
||
18 | Equipment, |
||
19 | Header, |
||
20 | Symbol, |
||
21 | OPC, |
||
22 | } |
||
23 | |||
24 | 45529c16 | LJIYEON | public enum ErrorType |
25 | { |
||
26 | Error = -1, |
||
27 | OK, |
||
28 | InValid //이값은 들어가는데가 없음.. |
||
29 | } |
||
30 | |||
31 | 2ada3be8 | LJIYEON | |
32 | |||
33 | |||
34 | 6b9e7a56 | gaqhf | public class PSN |
35 | { |
||
36 | 8f24b438 | gaqhf | private double[] DrawingSize = null; |
37 | private double DrawingWidth = double.NaN; |
||
38 | private double DrawingHeight = double.NaN; |
||
39 | public int Revision; |
||
40 | c6503eaa | gaqhf | public string EquipTagNoAttributeName = string.Empty; |
41 | 6b9e7a56 | gaqhf | public DataTable PathItems { get; set; } |
42 | public DataTable SequenceData { get; set; } |
||
43 | public DataTable PipeSystemNetwork { get; set; } |
||
44 | 36a45f13 | gaqhf | public DataTable TopologySet { get; set; } |
45 | 6b9e7a56 | gaqhf | public DataTable Equipment { get; set; } |
46 | public DataTable Nozzle { get; set; } |
||
47 | |||
48 | 2ada3be8 | LJIYEON | |
49 | public string Rule1 = ""; |
||
50 | public string Rule2 = ""; |
||
51 | public string Rule3 = ""; |
||
52 | public string Rule4 = ""; |
||
53 | public string Rule5 = ""; |
||
54 | |||
55 | 6b9e7a56 | gaqhf | List<Document> Documents; |
56 | List<Group> groups = new List<Group>(); |
||
57 | List<PSNItem> PSNItems = new List<PSNItem>(); |
||
58 | List<Topology> Topologies = new List<Topology>(); |
||
59 | |||
60 | DataTable opcDT = null; |
||
61 | DataTable topologyRuleDT = null; |
||
62 | |||
63 | 5dfc785c | LJIYEON | ID2Info id2Info = ID2Info.GetInstance(); |
64 | |||
65 | 6b9e7a56 | gaqhf | const string FluidPriorityType = "FLUIDCODE"; |
66 | const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS"; |
||
67 | |||
68 | 5c248ee3 | gaqhf | public PSN() |
69 | { |
||
70 | |||
71 | } |
||
72 | |||
73 | 8f24b438 | gaqhf | public PSN(List<Document> documents, int Revision) |
74 | 6b9e7a56 | gaqhf | { |
75 | 5dfc785c | LJIYEON | try |
76 | { |
||
77 | Documents = documents; |
||
78 | foreach (Document document in Documents) |
||
79 | groups.AddRange(document.Groups); |
||
80 | opcDT = GetOPCInfo(); |
||
81 | topologyRuleDT = GetTopologyRule(); |
||
82 | this.Revision = Revision; |
||
83 | DrawingSize = DB.GetDrawingSize(); |
||
84 | if (DrawingSize == null) |
||
85 | { |
||
86 | MessageBox.Show("There is no data whose Section is Area and Key is Drawing in the drawing table.", "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
87 | return; |
||
88 | } |
||
89 | DrawingWidth = DrawingSize[2] - DrawingSize[0]; |
||
90 | DrawingHeight = DrawingSize[3] - DrawingSize[1]; |
||
91 | } |
||
92 | catch (Exception ex) |
||
93 | { |
||
94 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
95 | MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
96 | } |
||
97 | 6b9e7a56 | gaqhf | } |
98 | |||
99 | 36a45f13 | gaqhf | private string GetItemTag(Item item) |
100 | { |
||
101 | string result = string.Empty; |
||
102 | if (item.ItemType == ItemType.Line) |
||
103 | result = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
||
104 | else if (item.ItemType == ItemType.Symbol && item.SubItemType == SubItemType.Nozzle) |
||
105 | result = Nozzle.Select(string.Format("OID = '{0}'", item.UID)).First()["ITEMTAG"].ToString(); |
||
106 | |||
107 | return result; |
||
108 | } |
||
109 | 7881ec8f | gaqhf | private string GetItemName(Item item, string itemOID) |
110 | { |
||
111 | string result = string.Empty; |
||
112 | if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
||
113 | { |
||
114 | if (itemOID.Contains("_")) |
||
115 | { |
||
116 | string split = itemOID.Split(new char[] { '_' })[1]; |
||
117 | if (split.StartsWith("B")) |
||
118 | result = "Branch"; |
||
119 | else |
||
120 | result = "PipeRun"; |
||
121 | } |
||
122 | else |
||
123 | result = "PipeRun"; |
||
124 | } |
||
125 | else if (item.ItemType == ItemType.Symbol) |
||
126 | { |
||
127 | if (item.ID2DBCategory == "Instrumentation") |
||
128 | result = "Instrument"; |
||
129 | else if (item.ID2DBType == "Nozzles") |
||
130 | result = "Nozzle"; |
||
131 | else if (item.ID2DBType == "Fittings" || |
||
132 | item.ID2DBType == "Piping OPC's" || |
||
133 | item.ID2DBType == "Specialty Components" || |
||
134 | item.ID2DBType == "Valves" || |
||
135 | item.ID2DBType == "Reducers") |
||
136 | result = "PipingComp"; |
||
137 | } |
||
138 | return result; |
||
139 | } |
||
140 | |||
141 | private string GetClass(Item item, string itemOID) |
||
142 | { |
||
143 | string result = string.Empty; |
||
144 | if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
||
145 | { |
||
146 | if (itemOID.Contains("_")) |
||
147 | { |
||
148 | string split = itemOID.Split(new char[] { '_' })[1]; |
||
149 | if (split.StartsWith("B")) |
||
150 | result = "Branch"; |
||
151 | else |
||
152 | result = "Piping"; |
||
153 | } |
||
154 | else |
||
155 | result = "Piping"; |
||
156 | } |
||
157 | else if (item.ItemType == ItemType.Symbol) |
||
158 | { |
||
159 | if (item.ID2DBCategory == "Instrumentation") |
||
160 | result = item.ID2DBType; |
||
161 | else if (item.ID2DBType == "Nozzles") |
||
162 | result = string.Empty; |
||
163 | else if (item.ID2DBType == "Fittings" || |
||
164 | item.ID2DBType == "Piping OPC's" || |
||
165 | item.ID2DBType == "Specialty Components" || |
||
166 | item.ID2DBType == "Valves" || |
||
167 | item.ID2DBType == "Reducers") |
||
168 | result = item.ID2DBType; |
||
169 | } |
||
170 | return result; |
||
171 | } |
||
172 | |||
173 | private string GetSubClass(Item item, string itemOID) |
||
174 | { |
||
175 | string result = string.Empty; |
||
176 | if (item.ItemType == ItemType.Line && (item.Name == "Secondary" || item.Name == "Primary")) |
||
177 | { |
||
178 | if (itemOID.Contains("_")) |
||
179 | { |
||
180 | string split = itemOID.Split(new char[] { '_' })[1]; |
||
181 | if (split.StartsWith("B")) |
||
182 | result = "Tee"; |
||
183 | else |
||
184 | result = ""; |
||
185 | } |
||
186 | else |
||
187 | result = ""; |
||
188 | } |
||
189 | else if (item.ItemType == ItemType.Symbol) |
||
190 | { |
||
191 | if (item.ID2DBCategory == "Instrumentation") |
||
192 | result = string.Empty; |
||
193 | else if (item.ID2DBType == "Nozzles") |
||
194 | result = string.Empty; |
||
195 | else if (item.ID2DBType == "Fittings" || |
||
196 | item.ID2DBType == "Piping OPC's" || |
||
197 | item.ID2DBType == "Specialty Components" || |
||
198 | item.ID2DBType == "Valves" || |
||
199 | item.ID2DBType == "Reducers") |
||
200 | result = "In-line component"; |
||
201 | } |
||
202 | return result; |
||
203 | } |
||
204 | 36a45f13 | gaqhf | |
205 | 6b9e7a56 | gaqhf | public void SetPSNData() |
206 | { |
||
207 | 7881ec8f | gaqhf | // Item들의 속성으로 Topology Data를 생성한다. |
208 | // Topology Data는 Topology Rule Setting을 기준으로 생성한다. |
||
209 | 6b9e7a56 | gaqhf | SetTopologyData(); |
210 | 7881ec8f | gaqhf | // ID2의 OPC연결 Data 기반으로 Group(도면단위 PSN)을 연결한다. |
211 | 6b9e7a56 | gaqhf | ConnectByOPC(); |
212 | 7881ec8f | gaqhf | // 실제 PSN 생성 로직 |
213 | // 연결된 Group을 하나의 PSN으로 만든다. |
||
214 | 6b9e7a56 | gaqhf | SetPSNItem(); |
215 | 7881ec8f | gaqhf | // 생성된 PSN의 Type을 설정한다. |
216 | 6b9e7a56 | gaqhf | SetPSNType(); |
217 | 7881ec8f | gaqhf | // ID2에는 Branch 정보가 없어서 Branch 정보를 생성한다. |
218 | 6b9e7a56 | gaqhf | SetBranchInfo(); |
219 | 7881ec8f | gaqhf | // 생성된 Topology Data들을 정리하며 Main, Branch를 판단한다. |
220 | 6b9e7a56 | gaqhf | SetTopology(); |
221 | 7881ec8f | gaqhf | // PSN이 Bypass인지 검사 |
222 | SetPSNBypass(); |
||
223 | // Topology들에게 Index를 부여한다 |
||
224 | SetTopologyIndex(); |
||
225 | |||
226 | // Nozzle, Equipment의 정보를 저장 |
||
227 | 6b9e7a56 | gaqhf | SaveNozzleAndEquipment(); |
228 | 7881ec8f | gaqhf | // PSN의 정보를 저장 |
229 | 6b9e7a56 | gaqhf | SavePSNData(); |
230 | 7881ec8f | gaqhf | // Topology의 subtype을 update(bypass, Header, 등등) |
231 | UpdateSubType(); |
||
232 | // Update Error |
||
233 | f89175b9 | gaqhf | //UpdateErrorForPSN(); |
234 | 6b9e7a56 | gaqhf | } |
235 | 7881ec8f | gaqhf | |
236 | 6b9e7a56 | gaqhf | private void SetTopologyData() |
237 | { |
||
238 | foreach (Document document in Documents) |
||
239 | { |
||
240 | foreach (Item item in document.Items) |
||
241 | { |
||
242 | item.TopologyData = string.Empty; |
||
243 | 8f24b438 | gaqhf | item.PSNPipeLineID = string.Empty; |
244 | 6b9e7a56 | gaqhf | LineNumber lineNumber = document.LineNumbers.Find(x => x.UID == item.Owner); |
245 | if (lineNumber != null) |
||
246 | { |
||
247 | item.LineNumber = lineNumber; |
||
248 | |||
249 | foreach (DataRow row in topologyRuleDT.Rows) |
||
250 | { |
||
251 | string uid = row["UID"].ToString(); |
||
252 | if (uid == "-") |
||
253 | item.TopologyData += "-"; |
||
254 | else |
||
255 | { |
||
256 | f25b787a | gaqhf | Attribute itemAttr = item.Attributes.Find(x => x.Name == uid); |
257 | |||
258 | Attribute attribute = lineNumber.Attributes.Find(x => x.Name == uid); |
||
259 | 6b9e7a56 | gaqhf | if (attribute != null) |
260 | item.TopologyData += attribute.Value; |
||
261 | } |
||
262 | } |
||
263 | 8f24b438 | gaqhf | |
264 | Attribute insulAttr = item.LineNumber.Attributes.Find(x => x.Name == "InsulationPurpose"); |
||
265 | 0f07fa34 | gaqhf | if (insulAttr != null && !string.IsNullOrEmpty(insulAttr.Value)) |
266 | 8f24b438 | gaqhf | item.PSNPipeLineID = item.TopologyData + "-" + insulAttr.Value; |
267 | else |
||
268 | item.PSNPipeLineID = item.TopologyData; |
||
269 | 6b9e7a56 | gaqhf | } |
270 | 0f07fa34 | gaqhf | else |
271 | { |
||
272 | item.TopologyData = "Empty LineNumber"; |
||
273 | item.LineNumber = new LineNumber(); |
||
274 | } |
||
275 | 6b9e7a56 | gaqhf | } |
276 | } |
||
277 | |||
278 | 0f07fa34 | gaqhf | int emptyIndex = 1; |
279 | foreach (Group group in groups) |
||
280 | { |
||
281 | List<Item> groupItems = group.Items.FindAll(x => x.TopologyData == "Empty LineNumber"); |
||
282 | if (groupItems.Count > 0) |
||
283 | { |
||
284 | foreach (var item in groupItems) |
||
285 | item.TopologyData += string.Format("-{0}", emptyIndex); |
||
286 | emptyIndex++; |
||
287 | } |
||
288 | } |
||
289 | 6b9e7a56 | gaqhf | |
290 | } |
||
291 | private void ConnectByOPC() |
||
292 | { |
||
293 | foreach (Group group in groups.FindAll(x => x.Items.Last().SubItemType == SubItemType.OPC)) |
||
294 | { |
||
295 | Item opcItem = group.Items.Last(); |
||
296 | DataRow[] fromRows = opcDT.Select(string.Format("FromOPCUID = '{0}'", opcItem.UID)); |
||
297 | if (fromRows.Length.Equals(1)) |
||
298 | { |
||
299 | DataRow opcRow = fromRows.First(); |
||
300 | string toDrawing = opcRow["ToDrawing"].ToString(); |
||
301 | string toOPCUID = opcRow["ToOPCUID"].ToString(); |
||
302 | |||
303 | Document toDocument = Documents.Find(x => x.DrawingName == toDrawing); |
||
304 | 0fe04b33 | LJIYEON | if(toDocument != null) |
305 | { |
||
306 | Group toGroup = toDocument.Groups.Find(x => x.Items.Find(y => y.UID == toOPCUID) != null); |
||
307 | group.EndGroup = toGroup; |
||
308 | toGroup.StartGroup = group; |
||
309 | } |
||
310 | 6b9e7a56 | gaqhf | } |
311 | } |
||
312 | } |
||
313 | private void SetPSNItem() |
||
314 | { |
||
315 | Dictionary<Group, string> groupDic = new Dictionary<Group, string>(); |
||
316 | foreach (Group group in groups) |
||
317 | groupDic.Add(group, Guid.NewGuid().ToString()); |
||
318 | |||
319 | foreach (Group group in groups) |
||
320 | { |
||
321 | string groupKey = groupDic[group]; |
||
322 | if (group.StartGroup != null) |
||
323 | { |
||
324 | string otherKey = groupDic[group.StartGroup]; |
||
325 | ChangeGroupID(otherKey, groupKey); |
||
326 | } |
||
327 | } |
||
328 | |||
329 | // PSN 정리 |
||
330 | foreach (var item in groupDic) |
||
331 | { |
||
332 | Group group = item.Key; |
||
333 | string uid = item.Value; |
||
334 | PSNItem PSNItem = PSNItems.Find(x => x.UID == uid); |
||
335 | if (PSNItem == null) |
||
336 | { |
||
337 | 8f24b438 | gaqhf | PSNItem = new PSNItem(PSNItems.Count, Revision) { UID = uid }; |
338 | 6b9e7a56 | gaqhf | PSNItems.Add(PSNItem); |
339 | } |
||
340 | PSNItem.Groups.Add(group); |
||
341 | 36a45f13 | gaqhf | foreach (Item groupItem in group.Items) |
342 | groupItem.PSNItem = PSNItem; |
||
343 | 6b9e7a56 | gaqhf | } |
344 | |||
345 | // Sort PSN |
||
346 | foreach (PSNItem PSNItem in PSNItems) |
||
347 | { |
||
348 | List<Group> _groups = new List<Group>(); |
||
349 | |||
350 | Stack<Group> stacks = new Stack<Group>(); |
||
351 | stacks.Push(PSNItem.Groups.First()); |
||
352 | while (stacks.Count > 0) |
||
353 | { |
||
354 | Group stack = stacks.Pop(); |
||
355 | if (_groups.Contains(stack)) |
||
356 | continue; |
||
357 | |||
358 | if (_groups.Count == 0) |
||
359 | _groups.Add(stack); |
||
360 | else |
||
361 | { |
||
362 | if (stack.StartGroup != null && _groups.Contains(stack.StartGroup)) |
||
363 | { |
||
364 | int index = _groups.IndexOf(stack.StartGroup); |
||
365 | _groups.Insert(index + 1, stack); |
||
366 | } |
||
367 | else if (stack.EndGroup != null && _groups.Contains(stack.EndGroup)) |
||
368 | { |
||
369 | int index = _groups.IndexOf(stack.EndGroup); |
||
370 | _groups.Insert(index, stack); |
||
371 | } |
||
372 | } |
||
373 | |||
374 | if (stack.StartGroup != null) |
||
375 | stacks.Push(stack.StartGroup); |
||
376 | if (stack.EndGroup != null) |
||
377 | stacks.Push(stack.EndGroup); |
||
378 | } |
||
379 | |||
380 | PSNItem.Groups.Clear(); |
||
381 | PSNItem.Groups.AddRange(_groups); |
||
382 | } |
||
383 | |||
384 | void ChangeGroupID(string from, string to) |
||
385 | { |
||
386 | if (from.Equals(to)) |
||
387 | return; |
||
388 | |||
389 | List<Group> changeItems = new List<Group>(); |
||
390 | foreach (var _item in groupDic) |
||
391 | if (_item.Value.Equals(from)) |
||
392 | changeItems.Add(_item.Key); |
||
393 | foreach (var _item in changeItems) |
||
394 | groupDic[_item] = to; |
||
395 | } |
||
396 | } |
||
397 | private void SetPSNType() |
||
398 | { |
||
399 | foreach (PSNItem PSNItem in PSNItems) |
||
400 | { |
||
401 | Group firstGroup = PSNItem.Groups.First(); |
||
402 | Group lastGroup = PSNItem.Groups.Last(); |
||
403 | |||
404 | Item firstItem = firstGroup.Items.First(); |
||
405 | Item lastItem = lastGroup.Items.Last(); |
||
406 | |||
407 | PSNItem.StartType = GetPSNType(firstItem, true); |
||
408 | PSNItem.EndType = GetPSNType(lastItem, false); |
||
409 | } |
||
410 | |||
411 | PSNType GetPSNType(Item item, bool bFirst = true) |
||
412 | { |
||
413 | PSNType type = PSNType.None; |
||
414 | |||
415 | if (item.ItemType == ItemType.Line) |
||
416 | { |
||
417 | Group group = groups.Find(x => x.Items.Contains(item)); |
||
418 | if (bFirst && item.Relations[0].Item != null && !group.Items.Contains(item.Relations[0].Item)) |
||
419 | { |
||
420 | Item connItem = item.Relations[0].Item; |
||
421 | if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
||
422 | type = PSNType.Branch; |
||
423 | else if (connItem.ItemType == ItemType.Symbol) |
||
424 | type = PSNType.Symbol; |
||
425 | } |
||
426 | else if (!bFirst && item.Relations[1].Item != null && !group.Items.Contains(item.Relations[1].Item)) |
||
427 | { |
||
428 | Item connItem = item.Relations[1].Item; |
||
429 | if (connItem.ItemType == ItemType.Line && !IsConnected(item, connItem)) |
||
430 | type = PSNType.Branch; |
||
431 | else if (connItem.ItemType == ItemType.Symbol) |
||
432 | type = PSNType.Symbol; |
||
433 | } |
||
434 | } |
||
435 | else if (item.ItemType == ItemType.Symbol) |
||
436 | { |
||
437 | if (item.SubItemType == SubItemType.Nozzle) |
||
438 | type = PSNType.Equipment; |
||
439 | else if (item.SubItemType == SubItemType.Header) |
||
440 | type = PSNType.Header; |
||
441 | else if (item.SubItemType == SubItemType.OPC) |
||
442 | type = PSNType.OPC; |
||
443 | } |
||
444 | |||
445 | return type; |
||
446 | } |
||
447 | } |
||
448 | private void SetBranchInfo() |
||
449 | { |
||
450 | foreach (Document document in Documents) |
||
451 | { |
||
452 | List<Item> lines = document.Items.FindAll(x => x.ItemType == ItemType.Line).ToList(); |
||
453 | foreach (Item line in lines) |
||
454 | { |
||
455 | double[] point = line.Relations[0].Point; |
||
456 | List<Item> connLines = lines.FindAll(x => x.Relations.Find(y => y.UID == line.UID) != null && line.Relations.Find(y => y.UID == x.UID) == null); |
||
457 | connLines.Sort(SortBranchLine); |
||
458 | line.BranchItems.AddRange(connLines); |
||
459 | |||
460 | int SortBranchLine(Item a, Item b) |
||
461 | { |
||
462 | double[] pointA = a.Relations[0].UID == line.UID ? a.Relations[0].Point : a.Relations[1].Point; |
||
463 | double distanceA = CalcPointToPointdDistance(point[0], point[1], pointA[0], pointA[1]); |
||
464 | |||
465 | double[] pointB = b.Relations[0].UID == line.UID ? b.Relations[0].Point : b.Relations[1].Point; |
||
466 | double distanceB = CalcPointToPointdDistance(point[0], point[1], pointB[0], pointB[1]); |
||
467 | |||
468 | // 내림차순 |
||
469 | return distanceA.CompareTo(distanceB); |
||
470 | } |
||
471 | double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
||
472 | { |
||
473 | return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
||
474 | } |
||
475 | } |
||
476 | } |
||
477 | } |
||
478 | private void SetTopology() |
||
479 | { |
||
480 | #region 기본 topology 정리 |
||
481 | foreach (PSNItem PSNItem in PSNItems) |
||
482 | { |
||
483 | Topology topology = null; |
||
484 | foreach (Group group in PSNItem.Groups) |
||
485 | { |
||
486 | foreach (Item item in group.Items) |
||
487 | { |
||
488 | if (string.IsNullOrEmpty(item.TopologyData)) |
||
489 | topology = null; |
||
490 | else |
||
491 | { |
||
492 | if (topology == null) |
||
493 | { |
||
494 | topology = new Topology() |
||
495 | { |
||
496 | ID = item.TopologyData |
||
497 | }; |
||
498 | Topologies.Add(topology); |
||
499 | |||
500 | if (!PSNItem.Topologies.Contains(topology)) |
||
501 | PSNItem.Topologies.Add(topology); |
||
502 | } |
||
503 | else |
||
504 | { |
||
505 | if (topology.ID != item.TopologyData) |
||
506 | { |
||
507 | topology = new Topology() |
||
508 | { |
||
509 | ID = item.TopologyData |
||
510 | }; |
||
511 | Topologies.Add(topology); |
||
512 | |||
513 | if (!PSNItem.Topologies.Contains(topology)) |
||
514 | PSNItem.Topologies.Add(topology); |
||
515 | } |
||
516 | } |
||
517 | |||
518 | item.Topology = topology; |
||
519 | topology.Items.Add(item); |
||
520 | } |
||
521 | } |
||
522 | } |
||
523 | } |
||
524 | #endregion |
||
525 | |||
526 | #region Type |
||
527 | List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
||
528 | foreach (string id in ids) |
||
529 | { |
||
530 | List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
||
531 | 678760c6 | gaqhf | |
532 | 6b9e7a56 | gaqhf | // Main |
533 | 678760c6 | gaqhf | List<Topology> mainTopologies = FindMainTopology(topologies); |
534 | foreach (Topology topology in mainTopologies) |
||
535 | topology.Type = "M"; |
||
536 | 6b9e7a56 | gaqhf | |
537 | // Branch |
||
538 | List<Topology> branchToplogies = topologies.FindAll(x => string.IsNullOrEmpty(x.Type)); |
||
539 | foreach (Topology topology in branchToplogies) |
||
540 | topology.Type = "B"; |
||
541 | } |
||
542 | #endregion |
||
543 | } |
||
544 | 7881ec8f | gaqhf | private void SetTopologyIndex() |
545 | { |
||
546 | List<string> ids = Topologies.Select(x => x.ID).Distinct().ToList(); |
||
547 | foreach (string id in ids) |
||
548 | { |
||
549 | List<Topology> topologies = Topologies.FindAll(x => x.ID == id); |
||
550 | |||
551 | // Main |
||
552 | List<Topology> mainTopologies = topologies.FindAll(x => x.Type == "M"); |
||
553 | foreach (Topology topology in mainTopologies) |
||
554 | topology.Index = mainTopologies.IndexOf(topology).ToString(); |
||
555 | |||
556 | // Branch |
||
557 | List<Topology> branchToplogies = topologies.FindAll(x => x.Type == "B"); |
||
558 | foreach (Topology topology in branchToplogies) |
||
559 | topology.Index = (branchToplogies.IndexOf(topology) + 1).ToString(); |
||
560 | } |
||
561 | } |
||
562 | private void SetPSNBypass() |
||
563 | { |
||
564 | foreach (PSNItem PSNItem in PSNItems) |
||
565 | PSNItem.IsBypass = IsBypass(PSNItem); |
||
566 | } |
||
567 | 6b9e7a56 | gaqhf | private List<Topology> FindMainTopology(List<Topology> data) |
568 | { |
||
569 | 678760c6 | gaqhf | DataTable nominalDiameterDT = DB.SelectNominalDiameter(); |
570 | DataTable PMCDT = DB.SelectPSNPIPINGMATLCLASS(); |
||
571 | DataTable fluidCodeDT = DB.SelectPSNFluidCode(); |
||
572 | |||
573 | List<Topology> main = new List<Topology>(); |
||
574 | main.AddRange(data); |
||
575 | 6b9e7a56 | gaqhf | // |
576 | 678760c6 | gaqhf | main = GetNozzleTopology(data); |
577 | if (main.Count == 1) |
||
578 | return main; |
||
579 | else |
||
580 | { |
||
581 | if (main.Count > 0) |
||
582 | main = GetPMCTopology(main); |
||
583 | else |
||
584 | main = GetPMCTopology(data); |
||
585 | |||
586 | if (main.Count == 1) |
||
587 | return main; |
||
588 | else |
||
589 | { |
||
590 | if (main.Count > 0) |
||
591 | main = GetDiaTopology(main); |
||
592 | else |
||
593 | main = GetDiaTopology(data); |
||
594 | |||
595 | |||
596 | if (main.Count == 1) |
||
597 | return main; |
||
598 | else |
||
599 | { |
||
600 | if (main.Count > 0) |
||
601 | main = GetItemTopology(main); |
||
602 | else |
||
603 | main = GetItemTopology(data); |
||
604 | } |
||
605 | } |
||
606 | } |
||
607 | |||
608 | List<Topology> GetNozzleTopology(List<Topology> topologies) |
||
609 | { |
||
610 | return topologies.FindAll(x => x.Items.Find(y => y.SubItemType == SubItemType.Nozzle) != null); |
||
611 | } |
||
612 | 6b9e7a56 | gaqhf | |
613 | 678760c6 | gaqhf | List<Topology> GetPMCTopology(List<Topology> topologies) |
614 | { |
||
615 | List<Topology> result = new List<Topology>(); |
||
616 | foreach (DataRow row in PMCDT.Rows) |
||
617 | { |
||
618 | string value = row["CODE"].ToString(); |
||
619 | foreach (Topology topology in topologies) |
||
620 | { |
||
621 | foreach (Item item in topology.Items) |
||
622 | { |
||
623 | if (item.LineNumber == null) |
||
624 | continue; |
||
625 | 0f07fa34 | gaqhf | Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "PipingMaterialsClass"); |
626 | if (attribute != null && value == attribute.Value) |
||
627 | 678760c6 | gaqhf | { |
628 | result.Add(topology); |
||
629 | break; |
||
630 | } |
||
631 | } |
||
632 | } |
||
633 | |||
634 | if (result.Count > 0) |
||
635 | break; |
||
636 | } |
||
637 | |||
638 | return result; |
||
639 | } |
||
640 | |||
641 | List<Topology> GetDiaTopology(List<Topology> topologies) |
||
642 | { |
||
643 | List<Topology> result = new List<Topology>(); |
||
644 | foreach (DataRow row in nominalDiameterDT.Rows) |
||
645 | { |
||
646 | string inchValue = row["InchStr"].ToString(); |
||
647 | string metricValue = row["MetricStr"].ToString(); |
||
648 | foreach (Topology topology in topologies) |
||
649 | { |
||
650 | foreach (Item item in topology.Items) |
||
651 | { |
||
652 | if (item.LineNumber == null) |
||
653 | continue; |
||
654 | 0f07fa34 | gaqhf | Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
655 | if (attribute != null && (inchValue == attribute.Value || metricValue == attribute.Value)) |
||
656 | 678760c6 | gaqhf | { |
657 | result.Add(topology); |
||
658 | break; |
||
659 | } |
||
660 | } |
||
661 | } |
||
662 | |||
663 | if (result.Count > 0) |
||
664 | break; |
||
665 | } |
||
666 | |||
667 | return result; |
||
668 | } |
||
669 | |||
670 | List<Topology> GetItemTopology(List<Topology> topologies) |
||
671 | { |
||
672 | return new List<Topology>() { topologies.OrderByDescending(x => x.Items.Count).ToList().First() }; |
||
673 | } |
||
674 | 6b9e7a56 | gaqhf | |
675 | 678760c6 | gaqhf | return main; |
676 | 6b9e7a56 | gaqhf | } |
677 | |||
678 | private DataTable GetOPCInfo() |
||
679 | { |
||
680 | DataTable opc = DB.SelectOPCRelations(); |
||
681 | DataTable drawing = DB.SelectDrawings(); |
||
682 | |||
683 | DataTable dt = new DataTable(); |
||
684 | dt.Columns.Add("FromDrawing", typeof(string)); |
||
685 | dt.Columns.Add("FromDrawingUID", typeof(string)); |
||
686 | dt.Columns.Add("FromOPCUID", typeof(string)); |
||
687 | dt.Columns.Add("ToDrawing", typeof(string)); |
||
688 | dt.Columns.Add("ToDrawingUID", typeof(string)); |
||
689 | dt.Columns.Add("ToOPCUID", typeof(string)); |
||
690 | foreach (DataRow row in opc.Rows) |
||
691 | { |
||
692 | string fromDrawingUID = row["From_Drawings_UID"] == null ? string.Empty : row["From_Drawings_UID"].ToString(); |
||
693 | string fromOPCUID = row["From_OPC_UID"] == null ? string.Empty : row["From_OPC_UID"].ToString(); |
||
694 | string toDrawingUID = row["To_Drawings_UID"] == null ? string.Empty : row["To_Drawings_UID"].ToString(); |
||
695 | string toOPCUID = row["To_OPC_UID"] == null ? string.Empty : row["To_OPC_UID"].ToString(); |
||
696 | if (!string.IsNullOrEmpty(toOPCUID)) |
||
697 | { |
||
698 | DataRow[] fromRows = drawing.Select(string.Format("UID = '{0}'", fromDrawingUID)); |
||
699 | DataRow[] toRows = drawing.Select(string.Format("UID = '{0}'", toDrawingUID)); |
||
700 | if (fromRows.Length.Equals(1) && toRows.Length.Equals(1)) |
||
701 | { |
||
702 | string fromDrawingName = Path.GetFileNameWithoutExtension(fromRows.First()["NAME"].ToString()); |
||
703 | string toDrawingName = Path.GetFileNameWithoutExtension(toRows.First()["NAME"].ToString()); |
||
704 | |||
705 | DataRow newRow = dt.NewRow(); |
||
706 | newRow["FromDrawing"] = fromDrawingName; |
||
707 | newRow["FromDrawingUID"] = fromDrawingUID; |
||
708 | newRow["FromOPCUID"] = fromOPCUID; |
||
709 | newRow["ToDrawing"] = toDrawingName; |
||
710 | newRow["ToDrawingUID"] = toDrawingUID; |
||
711 | newRow["ToOPCUID"] = toOPCUID; |
||
712 | |||
713 | dt.Rows.Add(newRow); |
||
714 | } |
||
715 | } |
||
716 | } |
||
717 | |||
718 | return dt; |
||
719 | } |
||
720 | private DataTable GetTopologyRule() |
||
721 | { |
||
722 | DataTable dt = DB.SelectTopologyRule(); |
||
723 | |||
724 | return dt; |
||
725 | } |
||
726 | private bool IsConnected(Item item1, Item item2) |
||
727 | { |
||
728 | if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
||
729 | item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
||
730 | return true; |
||
731 | else |
||
732 | return false; |
||
733 | } |
||
734 | |||
735 | private void SaveNozzleAndEquipment() |
||
736 | { |
||
737 | List<Item> nozzles = new List<Item>(); |
||
738 | List<Equipment> equipments = new List<Equipment>(); |
||
739 | foreach (Document document in Documents) |
||
740 | { |
||
741 | nozzles.AddRange(document.Items.FindAll(x => x.SubItemType == SubItemType.Nozzle)); |
||
742 | equipments.AddRange(document.Equipments); |
||
743 | } |
||
744 | |||
745 | |||
746 | DataTable nozzleDT = new DataTable(); |
||
747 | nozzleDT.Columns.Add("OID", typeof(string)); |
||
748 | nozzleDT.Columns.Add("ITEMTAG", typeof(string)); |
||
749 | nozzleDT.Columns.Add("XCOORDS", typeof(string)); |
||
750 | nozzleDT.Columns.Add("YCOORDS", typeof(string)); |
||
751 | nozzleDT.Columns.Add("Equipment_OID", typeof(string)); |
||
752 | nozzleDT.Columns.Add("FLUID", typeof(string)); |
||
753 | nozzleDT.Columns.Add("NPD", typeof(string)); |
||
754 | nozzleDT.Columns.Add("ROTATION", typeof(string)); |
||
755 | nozzleDT.Columns.Add("FlowDirection", typeof(string)); |
||
756 | |||
757 | foreach (Item item in nozzles) |
||
758 | { |
||
759 | DataRow row = nozzleDT.NewRow(); |
||
760 | row["OID"] = item.UID; |
||
761 | |||
762 | Relation relation = item.Relations.Find(x => equipments.Find(y => y.UID == x.UID) != null); |
||
763 | if (relation != null) |
||
764 | { |
||
765 | Equipment equipment = equipments.Find(x => x.UID == relation.UID); |
||
766 | equipment.Nozzles.Add(item); |
||
767 | 8f24b438 | gaqhf | row["ITEMTAG"] = string.Format("N-{0}", string.Format("{0:D3}", equipment.Nozzles.Count + 100)); |
768 | 6b9e7a56 | gaqhf | row["Equipment_OID"] = equipment.UID; |
769 | 4c76a67a | gaqhf | item.Equipment = equipment; |
770 | 6b9e7a56 | gaqhf | } |
771 | 8f24b438 | gaqhf | row["XCOORDS"] = (item.POINT[0] / DrawingWidth).ToString(); |
772 | row["YCOORDS"] = (item.POINT[1] / DrawingHeight).ToString(); |
||
773 | 6b9e7a56 | gaqhf | Attribute fluidAttr = item.LineNumber.Attributes.Find(x => x.Name == "FluidCode"); |
774 | row["FLUID"] = fluidAttr != null ? fluidAttr.Value : string.Empty; |
||
775 | Attribute npdAttr = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
||
776 | row["NPD"] = npdAttr != null ? npdAttr.Value : string.Empty; |
||
777 | f25b787a | gaqhf | |
778 | double angle = Math.PI * 2 - Convert.ToDouble(item.ANGLE); |
||
779 | if (angle >= Math.PI * 2) |
||
780 | angle = angle - Math.PI * 2; |
||
781 | row["ROTATION"] = angle.ToString(); |
||
782 | 6b9e7a56 | gaqhf | |
783 | if (item.Topology.Items.First().Equals(item)) |
||
784 | row["FlowDirection"] = "Outlet"; |
||
785 | else if (item.Topology.Items.Last().Equals(item)) |
||
786 | row["FlowDirection"] = "Inlet"; |
||
787 | else |
||
788 | row["FlowDirection"] = string.Empty; |
||
789 | |||
790 | nozzleDT.Rows.Add(row); |
||
791 | } |
||
792 | |||
793 | DataTable equipDT = new DataTable(); |
||
794 | equipDT.Columns.Add("OID", typeof(string)); |
||
795 | equipDT.Columns.Add("ITEMTAG", typeof(string)); |
||
796 | equipDT.Columns.Add("XCOORDS", typeof(string)); |
||
797 | equipDT.Columns.Add("YCOORDS", typeof(string)); |
||
798 | |||
799 | foreach (Equipment equipment in equipments) |
||
800 | { |
||
801 | DataRow row = equipDT.NewRow(); |
||
802 | row["OID"] = equipment.UID; |
||
803 | c6503eaa | gaqhf | if (!string.IsNullOrEmpty(EquipTagNoAttributeName)) |
804 | { |
||
805 | Attribute attribute = equipment.Attributes.Find(x => x.Name == EquipTagNoAttributeName); |
||
806 | if (attribute != null) |
||
807 | equipment.ItemTag = attribute.Value; |
||
808 | } |
||
809 | else |
||
810 | equipment.ItemTag = equipment.Name; |
||
811 | 6b9e7a56 | gaqhf | |
812 | c6503eaa | gaqhf | row["ITEMTAG"] = equipment.ItemTag; |
813 | 6b9e7a56 | gaqhf | List<double> xList = equipment.POINT.Select(x => x[0]).ToList(); |
814 | 8f24b438 | gaqhf | row["XCOORDS"] = (xList.Sum() / (double)xList.Count) / DrawingWidth; |
815 | 6b9e7a56 | gaqhf | |
816 | List<double> yList = equipment.POINT.Select(x => x[1]).ToList(); |
||
817 | 8f24b438 | gaqhf | row["YCOORDS"] = (yList.Sum() / (double)yList.Count) / DrawingHeight; |
818 | 6b9e7a56 | gaqhf | |
819 | equipDT.Rows.Add(row); |
||
820 | } |
||
821 | |||
822 | Equipment = equipDT; |
||
823 | Nozzle = nozzleDT; |
||
824 | } |
||
825 | private void SavePSNData() |
||
826 | { |
||
827 | 2c46461b | LJIYEON | try |
828 | 36a45f13 | gaqhf | { |
829 | 2c46461b | LJIYEON | DataTable pathItemsDT = new DataTable(); |
830 | pathItemsDT.Columns.Add("OID", typeof(string)); |
||
831 | pathItemsDT.Columns.Add("SequenceData_OID", typeof(string)); |
||
832 | pathItemsDT.Columns.Add("TopologySet_OID", typeof(string)); |
||
833 | pathItemsDT.Columns.Add("BranchTopologySet_OID", typeof(string)); |
||
834 | pathItemsDT.Columns.Add("PipeLine_OID", typeof(string)); |
||
835 | pathItemsDT.Columns.Add("ITEMNAME", typeof(string)); |
||
836 | pathItemsDT.Columns.Add("ITEMTAG", typeof(string)); |
||
837 | pathItemsDT.Columns.Add("Class", typeof(string)); |
||
838 | pathItemsDT.Columns.Add("SubClass", typeof(string)); |
||
839 | pathItemsDT.Columns.Add("TYPE", typeof(string)); |
||
840 | pathItemsDT.Columns.Add("PIDNAME", typeof(string)); |
||
841 | pathItemsDT.Columns.Add("NPD", typeof(string)); |
||
842 | pathItemsDT.Columns.Add("PipeSystemNetwork_OID", typeof(string)); |
||
843 | pathItemsDT.Columns.Add("ViewPipeSystemNetwork_OID", typeof(string)); |
||
844 | pathItemsDT.Columns.Add("PipeRun_OID", typeof(string)); |
||
845 | |||
846 | DataTable sequenceDataDT = new DataTable(); |
||
847 | sequenceDataDT.Columns.Add("OID", typeof(string)); |
||
848 | sequenceDataDT.Columns.Add("SERIALNUMBER", typeof(string)); |
||
849 | sequenceDataDT.Columns.Add("PathItem_OID", typeof(string)); |
||
850 | sequenceDataDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
||
851 | |||
852 | DataTable pipeSystemNetworkDT = new DataTable(); |
||
853 | pipeSystemNetworkDT.Columns.Add("OID", typeof(string)); |
||
854 | pipeSystemNetworkDT.Columns.Add("Type", typeof(string)); |
||
855 | pipeSystemNetworkDT.Columns.Add("OrderNumber", typeof(string)); |
||
856 | pipeSystemNetworkDT.Columns.Add("Pipeline_OID", typeof(string)); |
||
857 | pipeSystemNetworkDT.Columns.Add("FROM_DATA", typeof(string)); |
||
858 | pipeSystemNetworkDT.Columns.Add("TO_DATA", typeof(string)); |
||
859 | pipeSystemNetworkDT.Columns.Add("TopologySet_OID_Key", typeof(string)); |
||
860 | pipeSystemNetworkDT.Columns.Add("PSNRevisionNumber", typeof(string)); |
||
861 | pipeSystemNetworkDT.Columns.Add("PBS", typeof(string)); |
||
862 | pipeSystemNetworkDT.Columns.Add("PIDDrawings", typeof(string)); |
||
863 | pipeSystemNetworkDT.Columns.Add("Validity", typeof(string)); |
||
864 | pipeSystemNetworkDT.Columns.Add("Status", typeof(string)); |
||
865 | ddc1c369 | LJIYEON | pipeSystemNetworkDT.Columns.Add("IncludingVirtualData", typeof(string)); |
866 | pipeSystemNetworkDT.Columns.Add("PSNAccuracy", typeof(string)); |
||
867 | 2c46461b | LJIYEON | |
868 | DataTable topologySetDT = new DataTable(); |
||
869 | topologySetDT.Columns.Add("OID", typeof(string)); |
||
870 | topologySetDT.Columns.Add("Type", typeof(string)); |
||
871 | topologySetDT.Columns.Add("SubType", typeof(string)); |
||
872 | topologySetDT.Columns.Add("HeadItemTag", typeof(string)); |
||
873 | topologySetDT.Columns.Add("TailItemTag", typeof(string)); |
||
874 | topologySetDT.Columns.Add("HeadItemID", typeof(string)); |
||
875 | topologySetDT.Columns.Add("TailItemID", typeof(string)); |
||
876 | |||
877 | // Set Header Info |
||
878 | List<VentDrainInfo> VentDrainInfos = new List<VentDrainInfo>(); |
||
879 | DataTable dt = DB.SelectVentDrainSetting(); |
||
880 | foreach (DataRow row in dt.Rows) |
||
881 | 36a45f13 | gaqhf | { |
882 | 2c46461b | LJIYEON | string groupID = row["GROUP_ID"].ToString(); |
883 | string desc = row["DESCRIPTION"].ToString(); |
||
884 | int index = Convert.ToInt32(row["INDEX"]); |
||
885 | string name = row["NAME"].ToString(); |
||
886 | 36a45f13 | gaqhf | |
887 | 2c46461b | LJIYEON | VentDrainInfo ventDrainInfo = VentDrainInfos.Find(x => x.UID.Equals(groupID)); |
888 | if (ventDrainInfo == null) |
||
889 | 36a45f13 | gaqhf | { |
890 | 2c46461b | LJIYEON | ventDrainInfo = new VentDrainInfo(groupID); |
891 | ventDrainInfo.Description = desc; |
||
892 | VentDrainInfos.Add(ventDrainInfo); |
||
893 | 36a45f13 | gaqhf | } |
894 | |||
895 | 2c46461b | LJIYEON | ventDrainInfo.VentDrainItems.Add(new VentDrainItem() |
896 | { |
||
897 | Index = index, |
||
898 | Name = name |
||
899 | }); |
||
900 | } |
||
901 | |||
902 | // key = 미입력 branch |
||
903 | Dictionary<Item, Item> startBranchDic = new Dictionary<Item, Item>(); |
||
904 | Dictionary<Item, Item> endBranchDic = new Dictionary<Item, Item>(); |
||
905 | foreach (PSNItem PSNItem in PSNItems) |
||
906 | { |
||
907 | int psnOrder = 0; |
||
908 | int index = 0; |
||
909 | bool bPSNStart = true; |
||
910 | string sPSNData = string.Empty; |
||
911 | bool bVentDrain = false; |
||
912 | |||
913 | //VentDrain 검사 |
||
914 | if (PSNItem.Groups.Count.Equals(1)) |
||
915 | 36a45f13 | gaqhf | { |
916 | 2c46461b | LJIYEON | List<VentDrainInfo> endInfos = new List<VentDrainInfo>(); |
917 | Group group = PSNItem.Groups[0]; |
||
918 | 36a45f13 | gaqhf | for (int i = 0; i < group.Items.Count; i++) |
919 | { |
||
920 | 2c46461b | LJIYEON | Item item = group.Items[i]; |
921 | 36a45f13 | gaqhf | foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
922 | { |
||
923 | 7881ec8f | gaqhf | if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != group.Items.Count) |
924 | 36a45f13 | gaqhf | continue; |
925 | if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
||
926 | { |
||
927 | endInfos.Add(ventDrainInfo); |
||
928 | continue; |
||
929 | } |
||
930 | |||
931 | if (i + 1 == group.Items.Count && group.Items.Count.Equals(ventDrainInfo.VentDrainItems.Count)) |
||
932 | bVentDrain = true; |
||
933 | } |
||
934 | } |
||
935 | |||
936 | 2c46461b | LJIYEON | if (!bVentDrain) |
937 | 6b9e7a56 | gaqhf | { |
938 | 2c46461b | LJIYEON | endInfos = new List<VentDrainInfo>(); |
939 | for (int i = 0; i < group.Items.Count; i++) |
||
940 | { |
||
941 | Item item = group.Items[group.Items.Count - i - 1]; |
||
942 | foreach (VentDrainInfo ventDrainInfo in VentDrainInfos) |
||
943 | { |
||
944 | if (endInfos.Contains(ventDrainInfo) || ventDrainInfo.VentDrainItems.Count != group.Items.Count) |
||
945 | continue; |
||
946 | if (!ventDrainInfo.VentDrainItems[i].Name.Equals(item.Name)) |
||
947 | { |
||
948 | endInfos.Add(ventDrainInfo); |
||
949 | continue; |
||
950 | } |
||
951 | |||
952 | if (i + 1 == group.Items.Count && group.Items.Count.Equals(ventDrainInfo.VentDrainItems.Count)) |
||
953 | bVentDrain = true; |
||
954 | } |
||
955 | } |
||
956 | 6b9e7a56 | gaqhf | } |
957 | 2c46461b | LJIYEON | } |
958 | |||
959 | //PSN, PathItems, SequenceData 관련 |
||
960 | foreach (Group group in PSNItem.Groups) |
||
961 | { |
||
962 | foreach (Item item in group.Items) |
||
963 | 6b9e7a56 | gaqhf | { |
964 | 2c46461b | LJIYEON | if (item.BranchItems.Count == 0) |
965 | 6b9e7a56 | gaqhf | { |
966 | 2c46461b | LJIYEON | CreatePathItemsDataRow(item.UID, item.ID2DBType); |
967 | CreateSequenceDataDataRow(item.UID); |
||
968 | 6b9e7a56 | gaqhf | index++; |
969 | 2c46461b | LJIYEON | } |
970 | else |
||
971 | { |
||
972 | CreatePathItemsDataRow(item.UID + "_L1", item.ID2DBType); |
||
973 | CreateSequenceDataDataRow(item.UID + "_L1"); |
||
974 | 6b9e7a56 | gaqhf | index++; |
975 | 2c46461b | LJIYEON | for (int i = 0; i < item.BranchItems.Count; i++) |
976 | { |
||
977 | CreatePathItemsDataRow(string.Format(item.UID + "_B{0}", i + 1), "Branch", item.BranchItems[i].Topology.FullName, item.BranchItems[i]); |
||
978 | CreateSequenceDataDataRow(string.Format(item.UID + "_B{0}", i + 1)); |
||
979 | index++; |
||
980 | |||
981 | CreatePathItemsDataRow(string.Format(item.UID + "_L{0}", i + 2), item.ID2DBType); |
||
982 | CreateSequenceDataDataRow(string.Format(item.UID + "_L{0}", i + 2)); |
||
983 | index++; |
||
984 | |||
985 | if (item.BranchItems[i].Relations[0].Item != null && item.BranchItems[i].Relations[0].Item == item) |
||
986 | startBranchDic.Add(item.BranchItems[i], item); |
||
987 | else if (item.BranchItems[i].Relations[1].Item != null && item.BranchItems[i].Relations[1].Item == item) |
||
988 | endBranchDic.Add(item.BranchItems[i], item); |
||
989 | } |
||
990 | 6b9e7a56 | gaqhf | } |
991 | |||
992 | 2c46461b | LJIYEON | if (bPSNStart) |
993 | 94a117ca | gaqhf | { |
994 | CreatePipeSystemNetworkDataRow(); |
||
995 | sPSNData = item.TopologyData; |
||
996 | psnOrder++; |
||
997 | 2c46461b | LJIYEON | bPSNStart = false; |
998 | 94a117ca | gaqhf | } |
999 | 2c46461b | LJIYEON | else |
1000 | { |
||
1001 | if (item.TopologyData != sPSNData) |
||
1002 | { |
||
1003 | CreatePipeSystemNetworkDataRow(); |
||
1004 | sPSNData = item.TopologyData; |
||
1005 | psnOrder++; |
||
1006 | } |
||
1007 | } |
||
1008 | void CreatePathItemsDataRow(string itemOID, string itemType, string branchTopologyName = "", Item branchItem = null) |
||
1009 | { |
||
1010 | DataRow newRow = pathItemsDT.NewRow(); |
||
1011 | newRow["OID"] = itemOID; |
||
1012 | 6b9e7a56 | gaqhf | |
1013 | 2c46461b | LJIYEON | newRow["SequenceData_OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
1014 | 6b9e7a56 | gaqhf | |
1015 | 2c46461b | LJIYEON | newRow["TopologySet_OID"] = item.Topology.FullName; |
1016 | 6b9e7a56 | gaqhf | |
1017 | 2c46461b | LJIYEON | newRow["BranchTopologySet_OID"] = branchTopologyName; |
1018 | newRow["PipeLine_OID"] = item.PSNPipeLineID; |
||
1019 | newRow["ITEMNAME"] = GetItemName(item, itemOID); |
||
1020 | newRow["ITEMTAG"] = GetItemTag(item); |
||
1021 | newRow["Class"] = GetClass(item, itemOID); |
||
1022 | newRow["SubClass"] = GetSubClass(item, itemOID); |
||
1023 | 7881ec8f | gaqhf | |
1024 | 2c46461b | LJIYEON | if (item.ItemType == ItemType.Symbol) |
1025 | newRow["TYPE"] = item.ID2DBName; |
||
1026 | else if (item.ItemType == ItemType.Line) |
||
1027 | newRow["TYPE"] = item.ID2DBType; |
||
1028 | newRow["PIDNAME"] = group.Document.DrawingName; |
||
1029 | 6b9e7a56 | gaqhf | |
1030 | 2c46461b | LJIYEON | // NPD |
1031 | if (item.LineNumber != null) |
||
1032 | { |
||
1033 | Attribute attribute = item.LineNumber.Attributes.Find(x => x.Name == "NominalDiameter"); |
||
1034 | if (attribute != null) |
||
1035 | newRow["NPD"] = attribute.Value; |
||
1036 | } |
||
1037 | else |
||
1038 | newRow["NPD"] = null; |
||
1039 | 6b9e7a56 | gaqhf | |
1040 | 2c46461b | LJIYEON | newRow["PipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
1041 | if (branchItem == null) |
||
1042 | newRow["ViewPipeSystemNetwork_OID"] = PSNItem.PSN_OID(); |
||
1043 | else |
||
1044 | newRow["ViewPipeSystemNetwork_OID"] = branchItem.PSNItem.PSN_OID(); |
||
1045 | 6b9e7a56 | gaqhf | |
1046 | 2c46461b | LJIYEON | newRow["PipeRun_OID"] = item.LineNumber != null ? item.LineNumber.Name : string.Empty; |
1047 | 6b9e7a56 | gaqhf | |
1048 | 2c46461b | LJIYEON | pathItemsDT.Rows.Add(newRow); |
1049 | } |
||
1050 | void CreateSequenceDataDataRow(string itemOID) |
||
1051 | 94a117ca | gaqhf | { |
1052 | 2c46461b | LJIYEON | DataRow newRow = sequenceDataDT.NewRow(); |
1053 | newRow["OID"] = string.Format(item.Topology.FullName + "_{0}", index); |
||
1054 | newRow["SERIALNUMBER"] = string.Format("{0}", index); |
||
1055 | newRow["PathItem_OID"] = itemOID; |
||
1056 | newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
||
1057 | |||
1058 | sequenceDataDT.Rows.Add(newRow); |
||
1059 | } |
||
1060 | void CreatePipeSystemNetworkDataRow() |
||
1061 | { |
||
1062 | // VentDrain의 경우 제외 요청 |
||
1063 | if (bVentDrain) |
||
1064 | return; |
||
1065 | |||
1066 | 2ada3be8 | LJIYEON | List<double> lstAcc = new List<double>(); |
1067 | 2c46461b | LJIYEON | DataRow newRow = pipeSystemNetworkDT.NewRow(); |
1068 | newRow["OID"] = PSNItem.PSN_OID(); |
||
1069 | newRow["Type"] = PSNItem.GetPSNType(); |
||
1070 | newRow["OrderNumber"] = psnOrder; |
||
1071 | newRow["Pipeline_OID"] = item.PSNPipeLineID; |
||
1072 | 2ada3be8 | LJIYEON | string From_d = PSNItem.GetFromData(); |
1073 | string To_d = PSNItem.GetToData(); |
||
1074 | newRow["FROM_DATA"] = From_d; |
||
1075 | newRow["TO_DATA"] = To_d; |
||
1076 | 2c46461b | LJIYEON | newRow["TopologySet_OID_Key"] = item.Topology.FullName; |
1077 | newRow["PSNRevisionNumber"] = string.Format("V{0:D4}", Revision); |
||
1078 | newRow["PBS"] = PSNItem.GetPBSData(); |
||
1079 | newRow["Validity"] = PSNItem.Validity; |
||
1080 | newRow["Status"] = !string.IsNullOrEmpty(PSNItem.Status) ? PSNItem.Status.Remove(0, 2) : string.Empty; |
||
1081 | 2ada3be8 | LJIYEON | |
1082 | if(!string.IsNullOrEmpty(From_d) || !string.IsNullOrEmpty(To_d)) |
||
1083 | { |
||
1084 | if (From_d.Contains(Rule1) || To_d.Contains(Rule1)) |
||
1085 | lstAcc.Add(0.75); |
||
1086 | else if (From_d.Contains(Rule2) || To_d.Contains(Rule2)) |
||
1087 | lstAcc.Add(0.7); |
||
1088 | else if (From_d.Contains(Rule3) || To_d.Contains(Rule3)) |
||
1089 | lstAcc.Add(0.5); |
||
1090 | else if (From_d.Contains(Rule4) || To_d.Contains(Rule4)) |
||
1091 | lstAcc.Add(0.65); |
||
1092 | else if (From_d.Contains(Rule5) || To_d.Contains(Rule5)) |
||
1093 | lstAcc.Add(0.6); |
||
1094 | } |
||
1095 | |||
1096 | ddc1c369 | LJIYEON | newRow["IncludingVirtualData"] = !string.IsNullOrEmpty(PSNItem.IncludingVirtualData) ? PSNItem.IncludingVirtualData : "No"; |
1097 | 2ada3be8 | LJIYEON | PSNItem.PSNAccuracy = Convert.ToString(Math.Round(Convert.ToDouble(AccuracyCalculation(lstAcc)), 1)) + "%"; |
1098 | newRow["PSNAccuracy"] = PSNItem.PSNAccuracy; |
||
1099 | 2c46461b | LJIYEON | |
1100 | List<string> drawingNames = new List<string>(); |
||
1101 | foreach (Group _group in PSNItem.Groups) |
||
1102 | f25b787a | gaqhf | { |
1103 | 2c46461b | LJIYEON | if (!drawingNames.Contains(_group.Document.DrawingName)) |
1104 | { |
||
1105 | if (drawingNames.Count == 0) |
||
1106 | newRow["PIDDrawings"] = _group.Document.DrawingName; |
||
1107 | else |
||
1108 | newRow["PIDDrawings"] = newRow["PIDDrawings"] + ", " + _group.Document.DrawingName; |
||
1109 | drawingNames.Add(_group.Document.DrawingName); |
||
1110 | } |
||
1111 | 94a117ca | gaqhf | } |
1112 | 2c46461b | LJIYEON | pipeSystemNetworkDT.Rows.Add(newRow); |
1113 | 94a117ca | gaqhf | } |
1114 | } |
||
1115 | 6b9e7a56 | gaqhf | } |
1116 | 2c46461b | LJIYEON | //TopologySet 관련 |
1117 | foreach (Topology topology in PSNItem.Topologies) |
||
1118 | { |
||
1119 | DataRow newRow = topologySetDT.NewRow(); |
||
1120 | newRow["OID"] = topology.FullName; |
||
1121 | newRow["Type"] = topology.FullName.Split(new char[] { '-' }).Last().StartsWith("M") ? "Main" : "Branch"; |
||
1122 | if (bVentDrain) |
||
1123 | newRow["SubType"] = "Vent_Drain"; |
||
1124 | else |
||
1125 | newRow["SubType"] = null; |
||
1126 | newRow["HeadItemTag"] = GetItemTag(topology.Items.Last()); |
||
1127 | newRow["TailItemTag"] = GetItemTag(topology.Items.First()); |
||
1128 | newRow["HeadItemID"] = topology.Items.Last().UID; |
||
1129 | newRow["TailItemID"] = topology.Items.First().UID; |
||
1130 | topologySetDT.Rows.Add(newRow); |
||
1131 | } |
||
1132 | 6b9e7a56 | gaqhf | } |
1133 | |||
1134 | 2c46461b | LJIYEON | foreach (var item in startBranchDic) |
1135 | 5c248ee3 | gaqhf | { |
1136 | 2c46461b | LJIYEON | string uid = item.Key.UID; |
1137 | string topologyName = item.Value.Topology.FullName; |
||
1138 | DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
||
1139 | if (rows.Length == 1) |
||
1140 | rows.First()["BranchTopologySet_OID"] = topologyName; |
||
1141 | else if (rows.Length > 1) |
||
1142 | 5c248ee3 | gaqhf | { |
1143 | 2c46461b | LJIYEON | DataRow targetRow = null; |
1144 | int index = int.MaxValue; |
||
1145 | foreach (DataRow row in rows) |
||
1146 | 5c248ee3 | gaqhf | { |
1147 | 2c46461b | LJIYEON | string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
1148 | if (split.StartsWith("L")) |
||
1149 | 5c248ee3 | gaqhf | { |
1150 | 2c46461b | LJIYEON | int num = Convert.ToInt32(split.Remove(0, 1)); |
1151 | if (index > num) |
||
1152 | { |
||
1153 | index = num; |
||
1154 | targetRow = row; |
||
1155 | } |
||
1156 | 5c248ee3 | gaqhf | } |
1157 | } |
||
1158 | |||
1159 | 2c46461b | LJIYEON | if (targetRow != null) |
1160 | targetRow["BranchTopologySet_OID"] = topologyName; |
||
1161 | } |
||
1162 | 5c248ee3 | gaqhf | } |
1163 | 2c46461b | LJIYEON | foreach (var item in endBranchDic) |
1164 | 5c248ee3 | gaqhf | { |
1165 | 2c46461b | LJIYEON | string uid = item.Key.UID; |
1166 | string topologyName = item.Value.Topology.FullName; |
||
1167 | DataRow[] rows = pathItemsDT.Select(string.Format("OID LIKE '{0}%'", uid)); |
||
1168 | if (rows.Length == 1) |
||
1169 | rows.First()["BranchTopologySet_OID"] = topologyName; |
||
1170 | else if (rows.Length > 1) |
||
1171 | 5c248ee3 | gaqhf | { |
1172 | 2c46461b | LJIYEON | DataRow targetRow = null; |
1173 | int index = int.MinValue; |
||
1174 | foreach (DataRow row in rows) |
||
1175 | 5c248ee3 | gaqhf | { |
1176 | 2c46461b | LJIYEON | string split = row["OID"].ToString().Split(new char[] { '_' })[1]; |
1177 | if (split.StartsWith("L")) |
||
1178 | 5c248ee3 | gaqhf | { |
1179 | 2c46461b | LJIYEON | int num = Convert.ToInt32(split.Remove(0, 1)); |
1180 | if (index < num) |
||
1181 | { |
||
1182 | index = num; |
||
1183 | targetRow = row; |
||
1184 | } |
||
1185 | 5c248ee3 | gaqhf | } |
1186 | } |
||
1187 | |||
1188 | 2c46461b | LJIYEON | if (targetRow != null) |
1189 | targetRow["BranchTopologySet_OID"] = topologyName; |
||
1190 | } |
||
1191 | 5c248ee3 | gaqhf | } |
1192 | |||
1193 | 2c46461b | LJIYEON | PathItems = pathItemsDT; |
1194 | SequenceData = sequenceDataDT; |
||
1195 | PipeSystemNetwork = pipeSystemNetworkDT; |
||
1196 | TopologySet = topologySetDT; |
||
1197 | } |
||
1198 | catch (Exception ex) |
||
1199 | { |
||
1200 | Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
||
1201 | MessageBox.Show(ex.Message, "ID2 " + id2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
1202 | } |
||
1203 | 36a45f13 | gaqhf | } |
1204 | 2ada3be8 | LJIYEON | |
1205 | private double AccuracyCalculation(List<double> lstAcc) |
||
1206 | { |
||
1207 | double acc = 1; |
||
1208 | foreach(double lacc in lstAcc) |
||
1209 | { |
||
1210 | acc *= lacc; |
||
1211 | } |
||
1212 | acc = acc * 100; |
||
1213 | return acc; |
||
1214 | } |
||
1215 | |||
1216 | 7881ec8f | gaqhf | private void UpdateSubType() |
1217 | 36a45f13 | gaqhf | { |
1218 | foreach (PSNItem PSNItem in PSNItems) |
||
1219 | { |
||
1220 | 7881ec8f | gaqhf | if (PSNItem.IsBypass) |
1221 | 36a45f13 | gaqhf | { |
1222 | 7881ec8f | gaqhf | foreach (Topology topology in PSNItem.Topologies) |
1223 | 36a45f13 | gaqhf | { |
1224 | 7881ec8f | gaqhf | DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
1225 | if (rows.Length.Equals(1)) |
||
1226 | rows.First()["SubType"] = "Bypass"; |
||
1227 | 36a45f13 | gaqhf | } |
1228 | } |
||
1229 | 7881ec8f | gaqhf | |
1230 | if (PSNItem.StartType == PSNType.Header) |
||
1231 | { |
||
1232 | Topology topology = PSNItem.Topologies.First(); |
||
1233 | DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
||
1234 | if (rows.Length.Equals(1)) |
||
1235 | rows.First()["SubType"] = "Header"; |
||
1236 | } |
||
1237 | else if (PSNItem.EndType == PSNType.Header) |
||
1238 | { |
||
1239 | Topology topology = PSNItem.Topologies.Last(); |
||
1240 | DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
||
1241 | if (rows.Length.Equals(1)) |
||
1242 | rows.First()["SubType"] = "Header"; |
||
1243 | } |
||
1244 | 36a45f13 | gaqhf | } |
1245 | |||
1246 | 7881ec8f | gaqhf | foreach (Topology topology in Topologies) |
1247 | { |
||
1248 | DataRow[] rows = TopologySet.Select(string.Format("OID = '{0}'", topology.FullName)); |
||
1249 | if (rows.Length.Equals(1) && rows.First()["SubType"] == null || string.IsNullOrEmpty(rows.First()["SubType"].ToString())) |
||
1250 | { |
||
1251 | Item firstItem = topology.Items.First(); |
||
1252 | Item lastItem = topology.Items.Last(); |
||
1253 | |||
1254 | List<Relation> relations = new List<Relation>(); |
||
1255 | relations.AddRange(firstItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
||
1256 | relations.AddRange(lastItem.Relations.FindAll(x => x.Item != null && x.Item.Topology.ID != topology.ID)); |
||
1257 | |||
1258 | if (relations.Count > 0) |
||
1259 | rows.First()["SubType"] = "OtherSystem"; |
||
1260 | } |
||
1261 | } |
||
1262 | |||
1263 | foreach (DataRow row in TopologySet.Rows) |
||
1264 | if (row["SubType"] == null || string.IsNullOrEmpty(row["SubType"].ToString())) |
||
1265 | row["SubType"] = "Normal"; |
||
1266 | } |
||
1267 | private bool IsBypass(PSNItem PSNItem) |
||
1268 | { |
||
1269 | bool bResult = false; |
||
1270 | |||
1271 | if (PSNItem.GetPSNType() == "B2B") |
||
1272 | { |
||
1273 | Group firstGroup = PSNItem.Groups.First(); |
||
1274 | Group lastGroup = PSNItem.Groups.Last(); |
||
1275 | Item firstItem = firstGroup.Items.First(); |
||
1276 | Item lastItem = lastGroup.Items.Last(); |
||
1277 | |||
1278 | Item connectedFirstItem = GetConnectedItemByPSN(firstItem); |
||
1279 | Item connectedLastItem = GetConnectedItemByPSN(lastItem); |
||
1280 | 36a45f13 | gaqhf | |
1281 | 7881ec8f | gaqhf | if (connectedFirstItem.LineNumber != null && connectedLastItem.LineNumber != null && |
1282 | !string.IsNullOrEmpty(connectedFirstItem.LineNumber.Name) && !string.IsNullOrEmpty(connectedLastItem.LineNumber.Name) && |
||
1283 | connectedFirstItem.LineNumber.Name == connectedLastItem.LineNumber.Name) |
||
1284 | bResult = true; |
||
1285 | else if (connectedFirstItem.PSNItem == connectedLastItem.PSNItem) |
||
1286 | bResult = true; |
||
1287 | } |
||
1288 | 36a45f13 | gaqhf | |
1289 | Item GetConnectedItemByPSN(Item item) |
||
1290 | { |
||
1291 | Item result = null; |
||
1292 | |||
1293 | Relation relation = item.Relations.Find(x => x.Item != null && x.Item.PSNItem != item.PSNItem); |
||
1294 | if (relation != null) |
||
1295 | result = relation.Item; |
||
1296 | |||
1297 | return result; |
||
1298 | } |
||
1299 | 7881ec8f | gaqhf | |
1300 | return bResult; |
||
1301 | } |
||
1302 | private void UpdateErrorForPSN() |
||
1303 | { |
||
1304 | 45529c16 | LJIYEON | DataRow[] errorRows = PipeSystemNetwork.Select(string.Format(" Type = '{0}'", ErrorType.Error)); |
1305 | 7881ec8f | gaqhf | foreach (DataRow dataRow in errorRows) |
1306 | { |
||
1307 | PSNItem PSNItem = PSNItems.Find(x=>x.PSN_OID() == dataRow["OID"].ToString()); |
||
1308 | |||
1309 | if (PSNItem.StartType == PSNType.OPC) |
||
1310 | PSNItem.StartType = PSNType.Equipment; |
||
1311 | |||
1312 | if (PSNItem.EndType == PSNType.OPC) |
||
1313 | PSNItem.EndType = PSNType.Equipment; |
||
1314 | |||
1315 | dataRow["Type"] = PSNItem.GetPSNType(); |
||
1316 | 45529c16 | LJIYEON | } |
1317 | 6b9e7a56 | gaqhf | } |
1318 | } |
||
1319 | |||
1320 | public class PSNItem |
||
1321 | { |
||
1322 | 8f24b438 | gaqhf | public PSNItem(int count, int Revision) |
1323 | 6b9e7a56 | gaqhf | { |
1324 | Groups = new List<Group>(); |
||
1325 | Topologies = new List<Topology>(); |
||
1326 | 94a117ca | gaqhf | |
1327 | Index = count + 1; |
||
1328 | 8f24b438 | gaqhf | this.Revision = Revision; |
1329 | 6b9e7a56 | gaqhf | } |
1330 | 8f24b438 | gaqhf | private int Revision; |
1331 | 6b9e7a56 | gaqhf | public string UID { get; set; } |
1332 | public List<Group> Groups { get; set; } |
||
1333 | public List<Topology> Topologies { get; set; } |
||
1334 | public PSNType StartType { get; set; } |
||
1335 | public PSNType EndType { get; set; } |
||
1336 | 94a117ca | gaqhf | public int Index { get; set; } |
1337 | 36a45f13 | gaqhf | public string Validity { get; set; } |
1338 | public string Status { get; set; } |
||
1339 | ddc1c369 | LJIYEON | public string IncludingVirtualData { get; set; } |
1340 | public string PSNAccuracy { get; set; } |
||
1341 | |||
1342 | 94a117ca | gaqhf | public string PSN_OID() |
1343 | { |
||
1344 | 36a45f13 | gaqhf | return string.Format("V{0}-PSN-{1}", string.Format("{0:D4}", Revision), string.Format("{0:D5}", Index)); |
1345 | 94a117ca | gaqhf | } |
1346 | public string GetPSNType() |
||
1347 | { |
||
1348 | string result = string.Empty; |
||
1349 | |||
1350 | if (EnableType(StartType) && EnableType(EndType)) |
||
1351 | { |
||
1352 | if (StartType == PSNType.Equipment && EndType == PSNType.Equipment) |
||
1353 | result = "E2E"; |
||
1354 | else if (StartType == PSNType.Branch && EndType == PSNType.Branch) |
||
1355 | result = "B2B"; |
||
1356 | else if (StartType == PSNType.Header && EndType == PSNType.Header) |
||
1357 | result = "HD2"; |
||
1358 | |||
1359 | else if (StartType == PSNType.Equipment && EndType == PSNType.Branch) |
||
1360 | result = "E2B"; |
||
1361 | else if (StartType == PSNType.Branch && EndType == PSNType.Equipment) |
||
1362 | result = "B2E"; |
||
1363 | |||
1364 | else if (StartType == PSNType.Header && EndType == PSNType.Branch) |
||
1365 | result = "HDB"; |
||
1366 | else if (StartType == PSNType.Branch && EndType == PSNType.Header) |
||
1367 | result = "HDB"; |
||
1368 | |||
1369 | else if (StartType == PSNType.Header && EndType == PSNType.Equipment) |
||
1370 | result = "HDE"; |
||
1371 | else if (StartType == PSNType.Equipment && EndType == PSNType.Header) |
||
1372 | result = "HDE"; |
||
1373 | else |
||
1374 | result = "Error"; |
||
1375 | } |
||
1376 | else |
||
1377 | result = "Error"; |
||
1378 | |||
1379 | return result; |
||
1380 | |||
1381 | |||
1382 | } |
||
1383 | private bool EnableType(PSNType type) |
||
1384 | { |
||
1385 | bool result = false; |
||
1386 | |||
1387 | if (type == PSNType.Branch || |
||
1388 | type == PSNType.Equipment || |
||
1389 | type == PSNType.Header) |
||
1390 | { |
||
1391 | result = true; |
||
1392 | } |
||
1393 | |||
1394 | return result; |
||
1395 | } |
||
1396 | 7881ec8f | gaqhf | public bool IsBypass { get; set; } |
1397 | 94a117ca | gaqhf | |
1398 | public string GetFromData() |
||
1399 | { |
||
1400 | string result = string.Empty; |
||
1401 | if (StartType == PSNType.Header) |
||
1402 | result = "ENDOFHEADER"; |
||
1403 | else if (StartType == PSNType.Branch) |
||
1404 | 36a45f13 | gaqhf | { |
1405 | Item item = Groups.First().Items.First(); |
||
1406 | if (!string.IsNullOrEmpty(item.Relations.First().Item.LineNumber.Name)) |
||
1407 | result = item.Relations.First().Item.LineNumber.Name; |
||
1408 | else |
||
1409 | { |
||
1410 | Status += ", Missing LineNumber"; |
||
1411 | result = "Empty LineNumber"; |
||
1412 | } |
||
1413 | } |
||
1414 | 94a117ca | gaqhf | else if (StartType == PSNType.Equipment) |
1415 | c6503eaa | gaqhf | result = Groups.First().Items.First().Equipment.ItemTag; |
1416 | 94a117ca | gaqhf | else |
1417 | 36a45f13 | gaqhf | { |
1418 | Validity = "Error"; |
||
1419 | Item item = Groups.First().Items.First(); |
||
1420 | if (item.ItemType == ItemType.Symbol) |
||
1421 | { |
||
1422 | 7881ec8f | gaqhf | if (item.ID2DBType.Contains("OPC's")) |
1423 | 36a45f13 | gaqhf | Status += ", OPC Disconneted"; |
1424 | else |
||
1425 | Status += ", Missing ItemTag or Description"; |
||
1426 | |||
1427 | 7881ec8f | gaqhf | result = item.ID2DBName; |
1428 | 36a45f13 | gaqhf | } |
1429 | else if (item.ItemType == ItemType.Line) |
||
1430 | { |
||
1431 | Status += ", Line Disconnected"; |
||
1432 | result = !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber"; |
||
1433 | } |
||
1434 | else |
||
1435 | result = "Unknown"; |
||
1436 | } |
||
1437 | 94a117ca | gaqhf | |
1438 | return result; |
||
1439 | } |
||
1440 | |||
1441 | public string GetToData() |
||
1442 | { |
||
1443 | string result = string.Empty; |
||
1444 | if (EndType == PSNType.Header) |
||
1445 | result = "ENDOFHEADER"; |
||
1446 | else if (EndType == PSNType.Branch) |
||
1447 | 36a45f13 | gaqhf | { |
1448 | Item item = Groups.Last().Items.Last(); |
||
1449 | if (!string.IsNullOrEmpty(item.Relations.Last().Item.LineNumber.Name)) |
||
1450 | result = item.Relations.Last().Item.LineNumber.Name; |
||
1451 | else |
||
1452 | { |
||
1453 | Status += ", Missing LineNumber"; |
||
1454 | result = "Empty LineNumber"; |
||
1455 | } |
||
1456 | } |
||
1457 | 94a117ca | gaqhf | else if (EndType == PSNType.Equipment) |
1458 | c6503eaa | gaqhf | result = Groups.Last().Items.Last().Equipment.ItemTag; |
1459 | 36a45f13 | gaqhf | else |
1460 | { |
||
1461 | Validity = "Error"; |
||
1462 | Item item = Groups.Last().Items.Last(); |
||
1463 | if (item.ItemType == ItemType.Symbol) |
||
1464 | { |
||
1465 | 7881ec8f | gaqhf | if (item.ID2DBType.Contains("OPC's")) |
1466 | 36a45f13 | gaqhf | Status += ", OPC Disconneted"; |
1467 | else |
||
1468 | Status += ", Missing ItemTag or Description"; |
||
1469 | |||
1470 | 7881ec8f | gaqhf | result = item.ID2DBName; |
1471 | 36a45f13 | gaqhf | } |
1472 | else if (item.ItemType == ItemType.Line) |
||
1473 | { |
||
1474 | Status += ", Line Disconnected"; |
||
1475 | result = !string.IsNullOrEmpty(item.LineNumber.Name) ? item.LineNumber.Name : "Empty LineNumber"; |
||
1476 | } |
||
1477 | else |
||
1478 | result = "Unknown"; |
||
1479 | } |
||
1480 | 94a117ca | gaqhf | return result; |
1481 | } |
||
1482 | 7881ec8f | gaqhf | |
1483 | public string GetPBSData() |
||
1484 | { |
||
1485 | string result = string.Empty; |
||
1486 | List<string> PBSList = new List<string>(); |
||
1487 | if (Settings.Default.PBSSetting.Equals("Line Number")) |
||
1488 | { |
||
1489 | string attrValue = Settings.Default.PBSSettingValue; |
||
1490 | |||
1491 | foreach (Group group in Groups) |
||
1492 | { |
||
1493 | List<LineNumber> lineNumbers = group.Items.Select(x =>x.LineNumber).Distinct().ToList(); |
||
1494 | foreach (LineNumber lineNumber in lineNumbers) |
||
1495 | { |
||
1496 | Attribute attribute = lineNumber.Attributes.Find(x => x.Name == attrValue && !string.IsNullOrEmpty(x.Value)); |
||
1497 | if (attribute != null) |
||
1498 | { |
||
1499 | string value = attribute.Value; |
||
1500 | if (!PBSList.Contains(value)) |
||
1501 | PBSList.Add(value); |
||
1502 | } |
||
1503 | } |
||
1504 | } |
||
1505 | } |
||
1506 | else if (Settings.Default.PBSSetting.Equals("Item Attribute")) |
||
1507 | { |
||
1508 | string attrValue = Settings.Default.PBSSettingValue; |
||
1509 | |||
1510 | foreach (Group group in Groups) |
||
1511 | { |
||
1512 | List<Item> items = group.Items.FindAll(x => x.Attributes.Find(y => y.Name == attrValue && !string.IsNullOrEmpty(y.Value)) != null); |
||
1513 | foreach (Item item in items) |
||
1514 | { |
||
1515 | string value = item.Attributes.Find(x => x.Name == attrValue).Value; |
||
1516 | if (!PBSList.Contains(value)) |
||
1517 | PBSList.Add(value); |
||
1518 | } |
||
1519 | } |
||
1520 | } |
||
1521 | else if (Settings.Default.PBSSetting.Equals("Drawing No")) |
||
1522 | { |
||
1523 | string attrValue = Settings.Default.PBSSettingValue; |
||
1524 | |||
1525 | foreach (Group group in Groups) |
||
1526 | { |
||
1527 | List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
||
1528 | foreach (Document document in documents) |
||
1529 | { |
||
1530 | string name = document.DrawingName; |
||
1531 | |||
1532 | int startIndex = Settings.Default.PBSSettingStartValue; |
||
1533 | int endIndex = Settings.Default.PBSSettingEndValue; |
||
1534 | |||
1535 | string subStr = name.Substring(startIndex - 1, endIndex - startIndex + 1); |
||
1536 | if (!PBSList.Contains(subStr)) |
||
1537 | PBSList.Add(subStr); |
||
1538 | } |
||
1539 | } |
||
1540 | } |
||
1541 | else if (Settings.Default.PBSSetting.Equals("Unit Area")) |
||
1542 | { |
||
1543 | foreach (Group group in Groups) |
||
1544 | { |
||
1545 | List<Document> documents = group.Items.Select(x => x.Document).Distinct().ToList(); |
||
1546 | foreach (Document document in documents) |
||
1547 | { |
||
1548 | List<TextInfo> textInfos = document.TextInfos.FindAll(x => x.Area == "Unit"); |
||
1549 | foreach (TextInfo textInfo in textInfos) |
||
1550 | { |
||
1551 | if (!PBSList.Contains(textInfo.Value)) |
||
1552 | PBSList.Add(textInfo.Value); |
||
1553 | } |
||
1554 | } |
||
1555 | } |
||
1556 | } |
||
1557 | |||
1558 | foreach (var item in PBSList) |
||
1559 | { |
||
1560 | if (string.IsNullOrEmpty(result)) |
||
1561 | result = item; |
||
1562 | else |
||
1563 | result += ", " + item; |
||
1564 | } |
||
1565 | return result; |
||
1566 | } |
||
1567 | 6b9e7a56 | gaqhf | } |
1568 | } |