개정판 3ea27536
issue #000: 멀티웨이
Change-Id: I6206332c7f193218fca0d6beeeeba5fa15704697
DTI_PID/ID2PSN/Document.cs | ||
---|---|---|
239 | 239 |
} |
240 | 240 |
} |
241 | 241 |
} |
242 |
|
|
243 |
|
|
244 |
private void SetGroup() |
|
245 |
{ |
|
246 |
List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
|
247 |
|
|
248 |
List<Item> unasignedMultiwaySymbol = new List<Item>(); |
|
249 |
List<Item> asignedMultiwaySymbol = new List<Item>(); |
|
250 |
|
|
251 |
Dictionary<Item, string> itemDic = new Dictionary<Item, string>(); |
|
252 |
foreach (Item item in orderItems) |
|
253 |
itemDic.Add(item, Guid.NewGuid().ToString()); |
|
254 |
|
|
255 |
foreach (Item item in orderItems) |
|
256 |
{ |
|
257 |
string groupKey = itemDic[item]; |
|
258 |
if (item.ItemType == ItemType.Line) |
|
259 |
{ |
|
260 |
GroupingForwardLine(); |
|
261 |
GroupingBackwardLine(); |
|
262 |
} |
|
263 |
|
|
264 |
if (item == orderItems.Last()) |
|
265 |
{ |
|
266 |
foreach (var multiwaySymbol in unasignedMultiwaySymbol.Where(w => !asignedMultiwaySymbol.Contains(w))) |
|
267 |
{ |
|
268 |
List<Item> inLine = new List<Item>(); |
|
269 |
List<Item> outLine = new List<Item>(); |
|
270 |
inLine.AddRange(GetConnectedBackwardLines(multiwaySymbol)); |
|
271 |
outLine.AddRange(GetConnectedForwardLines(multiwaySymbol)); |
|
272 |
|
|
273 |
// in line 혹은 out line 이 1개 |
|
274 |
if (inLine.Count > 0 && outLine.Count > 0 && (inLine.Count == 1 || outLine.Count == 1)) |
|
275 |
{ |
|
276 |
Item standardLine = inLine.Count == 1 ? inLine[0] : outLine[0]; |
|
277 |
List<Item> watingLines = inLine.Count == 1 ? outLine : inLine; |
|
278 |
|
|
279 |
List<Item> sameOwnerLines = new List<Item>(); |
|
280 |
|
|
281 |
foreach (var watingLine in watingLines) |
|
282 |
{ |
|
283 |
if (IsSameOwner(standardLine, watingLine)) |
|
284 |
{ |
|
285 |
sameOwnerLines.Add(watingLine); |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
// 기준 라인이랑 라인 넘버가 같은 라인이 1개 => 바로 연결 |
|
290 |
if (sameOwnerLines.Count == 1) |
|
291 |
{ |
|
292 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
293 |
ChangeGroupID(itemDic[sameOwnerLines[0]], itemDic[standardLine]); |
|
294 |
} |
|
295 |
// 기준 라인이랑 라인 넘버가 같은 라인이 0개 |
|
296 |
else if (sameOwnerLines.Count == 0) |
|
297 |
{ |
|
298 |
// NPD 기준 내림차순 정렬 |
|
299 |
watingLines.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter")))); |
|
300 |
watingLines.Reverse(); |
|
301 |
|
|
302 |
double largeSize = StringToNumber(watingLines[0].GetAttributeByName("NominalDiameter")); |
|
303 |
// NPD가 큰 라인들을 선택 |
|
304 |
var largeLines = watingLines.Where(w => StringToNumber(w.GetAttributeByName("NominalDiameter")).Equals(largeSize)).ToList(); |
|
305 |
|
|
306 |
// NPD가 가장 큰 라인이 1개 |
|
307 |
if (largeLines.Count == 1) |
|
308 |
{ |
|
309 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
310 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
311 |
} |
|
312 |
else |
|
313 |
{ |
|
314 |
// NPD가 동일하게 가장 큰 라인이 여러개 |
|
315 |
Relation relation = multiwaySymbol.Relations.Find(x => x.Item == standardLine); |
|
316 |
int connectionIndex = multiwaySymbol.Relations.IndexOf(relation); |
|
317 |
|
|
318 |
if (connectionIndex == 0 || connectionIndex == 1) |
|
319 |
{ |
|
320 |
Item nextItem = (connectionIndex == 0) ? multiwaySymbol.Relations[1].Item : multiwaySymbol.Relations[0].Item; |
|
321 |
if (nextItem != null) |
|
322 |
{ |
|
323 |
var matches = largeLines.Where(w => w == nextItem).ToList(); |
|
324 |
// NPD가 큰 라인 중에 직선으로 연결된 라인이 있음 |
|
325 |
if (matches.Count == 1) |
|
326 |
{ |
|
327 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
328 |
ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]); |
|
329 |
} |
|
330 |
// 없음 => 랜덤 |
|
331 |
else |
|
332 |
{ |
|
333 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
334 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
else if (multiwaySymbol.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3) |
|
339 |
{ |
|
340 |
Item nextItem = (connectionIndex == 2) ? multiwaySymbol.Relations[3].Item : multiwaySymbol.Relations[2].Item; |
|
341 |
if (nextItem != null) |
|
342 |
{ |
|
343 |
var matches = largeLines.Where(w => w == nextItem).ToList(); |
|
344 |
// NPD가 큰 라인 중에 직선으로 연결된 라인이 있음 |
|
345 |
if (matches.Count == 1) |
|
346 |
{ |
|
347 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
348 |
ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]); |
|
349 |
} |
|
350 |
// 없음 => 랜덤 |
|
351 |
else |
|
352 |
{ |
|
353 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
354 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
355 |
} |
|
356 |
} |
|
357 |
} |
|
358 |
// 3 way에서 NPS가 가장 큰 라인이 2번 연결점에 연결됨 => 랜덤 |
|
359 |
else |
|
360 |
{ |
|
361 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
362 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
// 기준 라인이랑 라인 넘버가 같은 라인이 2~3개 => NPD가 큰 라인, 직선으로 연결된 라인이랑 연결 |
|
367 |
else |
|
368 |
{ |
|
369 |
// NPD 기준 내림차순 정렬 |
|
370 |
sameOwnerLines.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter")))); |
|
371 |
sameOwnerLines.Reverse(); |
|
372 |
|
|
373 |
double largeSize = StringToNumber(sameOwnerLines[0].GetAttributeByName("NominalDiameter")); |
|
374 |
// NPD가 큰 라인들을 선택 |
|
375 |
var largeLines = sameOwnerLines.Where(w => StringToNumber(w.GetAttributeByName("NominalDiameter")).Equals(largeSize)).ToList(); |
|
376 |
|
|
377 |
// NPD가 가장 큰 라인이 1개 |
|
378 |
if (largeLines.Count == 1) |
|
379 |
{ |
|
380 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
381 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
382 |
} |
|
383 |
else |
|
384 |
{ |
|
385 |
// NPD가 동일하게 가장 큰 라인이 여러개 |
|
386 |
Relation relation = multiwaySymbol.Relations.Find(x => x.Item == standardLine); |
|
387 |
int connectionIndex = multiwaySymbol.Relations.IndexOf(relation); |
|
388 |
|
|
389 |
if (connectionIndex == 0 || connectionIndex == 1) |
|
390 |
{ |
|
391 |
Item nextItem = (connectionIndex == 0) ? multiwaySymbol.Relations[1].Item : multiwaySymbol.Relations[0].Item; |
|
392 |
if (nextItem != null) |
|
393 |
{ |
|
394 |
var matches = largeLines.Where(w => w == nextItem).ToList(); |
|
395 |
// NPD가 큰 라인 중에 직선으로 연결된 라인이 있음 |
|
396 |
if (matches.Count == 1) |
|
397 |
{ |
|
398 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
399 |
ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]); |
|
400 |
} |
|
401 |
// 없음 => 랜덤 |
|
402 |
else |
|
403 |
{ |
|
404 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
405 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
else if (multiwaySymbol.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3) |
|
410 |
{ |
|
411 |
Item nextItem = (connectionIndex == 2) ? multiwaySymbol.Relations[3].Item : multiwaySymbol.Relations[2].Item; |
|
412 |
if (nextItem != null) |
|
413 |
{ |
|
414 |
var matches = largeLines.Where(w => w == nextItem).ToList(); |
|
415 |
// NPD가 큰 라인 중에 직선으로 연결된 라인이 있음 |
|
416 |
if (matches.Count == 1) |
|
417 |
{ |
|
418 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
419 |
ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]); |
|
420 |
} |
|
421 |
// 없음 => 랜덤 |
|
422 |
else |
|
423 |
{ |
|
424 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
425 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
// 3 way에서 NPS가 가장 큰 라인이 2번 연결점에 연결됨 => 랜덤 |
|
430 |
else |
|
431 |
{ |
|
432 |
ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]); |
|
433 |
ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]); |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
440 |
|
|
441 |
void GroupingForwardLine() |
|
442 |
{ |
|
443 |
Item connItem = item.Relations[1].Item; |
|
444 |
if (connItem != null && IsConnected(connItem, item)) |
|
445 |
{ |
|
446 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item)) |
|
447 |
ChangeGroupID(itemDic[connItem], groupKey); |
|
448 |
else if (connItem.ItemType == ItemType.Symbol) |
|
449 |
{ |
|
450 |
List<Item> allConnItems = GetConnectedLines(connItem); |
|
451 |
allConnItems.Remove(item); |
|
452 |
List<Item> connItems = GetConnectedForwardLines(connItem); |
|
453 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
|
454 |
{ |
|
455 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
|
456 |
foreach (Item loopItem in connSymbols) |
|
457 |
ChangeGroupID(itemDic[loopItem], groupKey); |
|
458 |
} |
|
459 |
else |
|
460 |
{ |
|
461 |
List<Item> endItems = new List<Item>(); |
|
462 |
Stack<Item> stacks = new Stack<Item>(); |
|
463 |
Item preItem = item; |
|
464 |
stacks.Push(connItem); |
|
465 |
while (stacks.Count > 0) |
|
466 |
{ |
|
467 |
Item stack = stacks.Pop(); |
|
468 |
if (endItems.Contains(stack)) |
|
469 |
continue; |
|
470 |
endItems.Add(stack); |
|
471 |
|
|
472 |
if (GetConnectedItemCount(stack) < 3) |
|
473 |
{ |
|
474 |
ChangeGroupID(itemDic[stack], groupKey); |
|
475 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
476 |
foreach (Relation relation in relations) |
|
477 |
stacks.Push(relation.Item); |
|
478 |
preItem = stack; |
|
479 |
} |
|
480 |
else |
|
481 |
{ |
|
482 |
if (!unasignedMultiwaySymbol.Contains(stack)) |
|
483 |
unasignedMultiwaySymbol.Add(stack); |
|
484 |
} |
|
485 |
} |
|
486 |
} |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
|
|
491 |
|
|
492 |
void GroupingBackwardLine() |
|
493 |
{ |
|
494 |
Item connItem = item.Relations[0].Item; |
|
495 |
if (connItem != null && IsConnected(connItem, item)) |
|
496 |
{ |
|
497 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item)) |
|
498 |
ChangeGroupID(itemDic[connItem], groupKey); |
|
499 |
else if (connItem.ItemType == ItemType.Symbol) |
|
500 |
{ |
|
501 |
List<Item> allConnItems = GetConnectedLines(connItem); |
|
502 |
allConnItems.Remove(item); |
|
503 |
List<Item> connItems = GetConnectedBackwardLines(connItem); |
|
504 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
|
505 |
{ |
|
506 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
|
507 |
foreach (Item loopItem in connSymbols) |
|
508 |
ChangeGroupID(itemDic[loopItem], groupKey); |
|
509 |
} |
|
510 |
else |
|
511 |
{ |
|
512 |
List<Item> endItems = new List<Item>(); |
|
513 |
Stack<Item> stacks = new Stack<Item>(); |
|
514 |
Item preItem = item; |
|
515 |
stacks.Push(connItem); |
|
516 |
while (stacks.Count > 0) |
|
517 |
{ |
|
518 |
Item stack = stacks.Pop(); |
|
519 |
if (endItems.Contains(stack)) |
|
520 |
continue; |
|
521 |
endItems.Add(stack); |
|
522 |
|
|
523 |
Item nextSymbol; |
|
524 |
|
|
525 |
if (GetConnectedItemCount(stack) < 3) |
|
526 |
{ |
|
527 |
ChangeGroupID(itemDic[stack], groupKey); |
|
528 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
529 |
foreach (Relation relation in relations) |
|
530 |
stacks.Push(relation.Item); |
|
531 |
preItem = stack; |
|
532 |
} |
|
533 |
else |
|
534 |
{ |
|
535 |
if (!unasignedMultiwaySymbol.Contains(stack)) |
|
536 |
unasignedMultiwaySymbol.Add(stack); |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
bool MultiwayBackward(Item stack, Item beforeItem, out Item nextSymbol) |
|
545 |
{ |
|
546 |
nextSymbol = null; |
|
547 |
if (!unasignedMultiwaySymbol.Contains(stack)) |
|
548 |
unasignedMultiwaySymbol.Add(stack); |
|
549 |
|
|
550 |
if (stack.pairItem != null && stack.pairItem != beforeItem) |
|
551 |
return false; |
|
552 |
|
|
553 |
try |
|
554 |
{ |
|
555 |
Relation relation = stack.Relations.Find(x => x.Item == beforeItem); |
|
556 |
if (relation == null) |
|
557 |
{ |
|
558 |
return false; |
|
559 |
} |
|
560 |
|
|
561 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item != beforeItem); |
|
562 |
return false; |
|
563 |
if (relations.Count() == 0) |
|
564 |
return false; |
|
565 |
|
|
566 |
var matches = relations.Where(x => IsSameOwner(beforeItem, x.Item)).ToList(); |
|
567 |
|
|
568 |
if (matches.Count().Equals(0)) |
|
569 |
return false; |
|
570 |
|
|
571 |
else if (matches.Count().Equals(1)) |
|
572 |
{ |
|
573 |
if (matches[0].Item.ItemType == ItemType.Line) |
|
574 |
{ |
|
575 |
List<Item> connItems = GetConnectedBackwardLines(stack); |
|
576 |
if (connItems.Contains(matches[0].Item)) |
|
577 |
{ |
|
578 |
stack.pairItem = matches[0].Item; |
|
579 |
return true; |
|
580 |
} |
|
581 |
} |
|
582 |
else |
|
583 |
{ |
|
584 |
stack.pairItem = matches[0].Item; |
|
585 |
nextSymbol = matches[0].Item; |
|
586 |
return true; |
|
587 |
} |
|
588 |
} |
|
589 |
else if (matches.Count().Equals(2)) |
|
590 |
{ |
|
591 |
List<Item> connItems = GetConnectedBackwardLines(stack); |
|
592 |
if (connItems.Count == 0) |
|
593 |
return false; |
|
594 |
else |
|
595 |
{ |
|
596 |
connItems = connItems.Where(x => IsSameOwner(beforeItem, x)).ToList(); |
|
597 |
} |
|
598 |
|
|
599 |
if (connItems.Count().Equals(1)) |
|
600 |
{ |
|
601 |
bool isvalid = false; |
|
602 |
Item matchedLine = GetConnectedMatchedLIne(matches.Where(x => x.Item != connItems[0]).First().Item, stack); |
|
603 |
if (matchedLine != null) |
|
604 |
{ |
|
605 |
string size1 = matchedLine.GetAttributeByName("Size"); |
|
606 |
string size2 = item.GetAttributeByName("Size"); |
|
607 |
if (!string.IsNullOrEmpty(size1) && !string.IsNullOrEmpty(size2) && size1 != "None" && size2 != "None") |
|
608 |
{ |
|
609 |
if (size1.Contains("\"") && InchToNumber(size1) < InchToNumber(size2)) |
|
610 |
{ |
|
611 |
isvalid = true; |
|
612 |
} |
|
613 |
else if (Convert.ToDouble(size1) < Convert.ToDouble(size2)) |
|
614 |
{ |
|
615 |
isvalid = true; |
|
616 |
} |
|
617 |
} |
|
618 |
else if (!string.IsNullOrEmpty(size2) && size2 != "None" && string.IsNullOrEmpty(size1)) |
|
619 |
{ |
|
620 |
isvalid = true; |
|
621 |
} |
|
622 |
} |
|
623 |
|
|
624 |
if (!isvalid) |
|
625 |
return false; |
|
626 |
|
|
627 |
if (matches.Where(x => x.Item == connItems[0]) != null) |
|
628 |
{ |
|
629 |
stack.pairItem = connItems[0]; |
|
630 |
return true; |
|
631 |
} |
|
632 |
else |
|
633 |
{ |
|
634 |
Item matechedSymbol = GetConnectedMatchedSymbol(connItems[0].Relations[1].Item, connItems[0], stack); |
|
635 |
if (matechedSymbol != null) |
|
636 |
{ |
|
637 |
stack.pairItem = matechedSymbol; |
|
638 |
nextSymbol = matechedSymbol; |
|
639 |
return true; |
|
640 |
} |
|
641 |
else |
|
642 |
{ |
|
643 |
return false; |
|
644 |
} |
|
645 |
} |
|
646 |
} |
|
647 |
else if (connItems.Count() > 1) |
|
648 |
{ |
|
649 |
return true;//pair아이템 필요할 수도 있음 |
|
650 |
|
|
651 |
} |
|
652 |
} |
|
653 |
else |
|
654 |
{ |
|
655 |
return true; |
|
656 |
} |
|
657 |
|
|
658 |
|
|
659 |
|
|
660 |
//if (relation == null) |
|
661 |
//{ |
|
662 |
// return false; |
|
663 |
//} |
|
664 |
//int connectionIndex = stack.Relations.IndexOf(relation); |
|
665 |
//if (connectionIndex == 0 || connectionIndex == 1) |
|
666 |
//{ |
|
667 |
// Item nextItem = (connectionIndex == 0) ? stack.Relations[1].Item : stack.Relations[0].Item; |
|
668 |
// if (nextItem != null) |
|
669 |
// { |
|
670 |
// if (nextItem.ItemType == ItemType.Line) |
|
671 |
// { |
|
672 |
// List<Item> connItems = GetConnectedBackwardLines(stack); |
|
673 |
// if (connItems.Contains(nextItem)) |
|
674 |
// { |
|
675 |
// stack.pairItem = nextItem; |
|
676 |
// return true; |
|
677 |
// } |
|
678 |
// } |
|
679 |
// else |
|
680 |
// { |
|
681 |
// stack.pairItem = nextItem; |
|
682 |
// nextSymbol = nextItem; |
|
683 |
// return true; |
|
684 |
// } |
|
685 |
// } |
|
686 |
//} |
|
687 |
//else if (stack.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3) |
|
688 |
//{ |
|
689 |
// Item nextItem = (connectionIndex == 2) ? stack.Relations[3].Item : stack.Relations[2].Item; |
|
690 |
// if (nextItem != null) |
|
691 |
// { |
|
692 |
// if (nextItem.ItemType == ItemType.Line) |
|
693 |
// { |
|
694 |
// List<Item> connItems = GetConnectedForwardLines(stack); |
|
695 |
// if (connItems.Contains(nextItem)) |
|
696 |
// { |
|
697 |
// stack.pairItem = nextItem; |
|
698 |
// return true; |
|
699 |
// } |
|
700 |
// } |
|
701 |
// else |
|
702 |
// { |
|
703 |
// stack.pairItem = nextItem; |
|
704 |
// nextSymbol = nextItem; |
|
705 |
// return true; |
|
706 |
// } |
|
707 |
// } |
|
708 |
//} |
|
709 |
} |
|
710 |
catch (Exception ex) |
|
711 |
{ |
|
712 |
//Log.Write(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + "Error Item : " + beforeItem.UID + ", Error stack : " + stack.UID + "\r\n"); |
|
713 |
//MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace + "\r\n", "ARS ID2", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
714 |
} |
|
715 |
|
|
716 |
return false; |
|
717 |
} |
|
718 |
//bool MultiwayBackward(Item stack, Item beforeItem, out Item nextSymbol) |
|
719 |
//{ |
|
720 |
// nextSymbol = null; |
|
721 |
// if (!unasignedMultiwaySymbol.Contains(stack)) |
|
722 |
// unasignedMultiwaySymbol.Add(stack); |
|
723 |
|
|
724 |
// if (stack.pairItem != null && stack.pairItem != beforeItem) |
|
725 |
// return false; |
|
726 |
|
|
727 |
// try |
|
728 |
// { |
|
729 |
// Relation relation = stack.Relations.Find(x => x.Item == beforeItem); |
|
730 |
// if (relation == null) |
|
731 |
// { |
|
732 |
// return false; |
|
733 |
// } |
|
734 |
// int connectionIndex = stack.Relations.IndexOf(relation); |
|
735 |
// if (connectionIndex == 0 || connectionIndex == 1) |
|
736 |
// { |
|
737 |
// Item nextItem = (connectionIndex == 0) ? stack.Relations[1].Item : stack.Relations[0].Item; |
|
738 |
// if (nextItem != null) |
|
739 |
// { |
|
740 |
// if (nextItem.ItemType == ItemType.Line) |
|
741 |
// { |
|
742 |
// List<Item> connItems = GetConnectedBackwardLines(stack); |
|
743 |
// if (connItems.Contains(nextItem)) |
|
744 |
// { |
|
745 |
// stack.pairItem = nextItem; |
|
746 |
// return true; |
|
747 |
// } |
|
748 |
// } |
|
749 |
// else |
|
750 |
// { |
|
751 |
// stack.pairItem = nextItem; |
|
752 |
// nextSymbol = nextItem; |
|
753 |
// return true; |
|
754 |
// } |
|
755 |
// } |
|
756 |
// } |
|
757 |
// else if (stack.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3) |
|
758 |
// { |
|
759 |
// Item nextItem = (connectionIndex == 2) ? stack.Relations[3].Item : stack.Relations[2].Item; |
|
760 |
// if (nextItem != null) |
|
761 |
// { |
|
762 |
// if (nextItem.ItemType == ItemType.Line) |
|
763 |
// { |
|
764 |
// List<Item> connItems = GetConnectedBackwardLines(stack); |
|
765 |
// if (connItems.Contains(nextItem)) |
|
766 |
// { |
|
767 |
// stack.pairItem = nextItem; |
|
768 |
// return true; |
|
769 |
// } |
|
770 |
// } |
|
771 |
// else |
|
772 |
// { |
|
773 |
// stack.pairItem = nextItem; |
|
774 |
// nextSymbol = nextItem; |
|
775 |
// return true; |
|
776 |
// } |
|
777 |
// } |
|
778 |
// } |
|
779 |
// } |
|
780 |
// catch (Exception ex) |
|
781 |
// { |
|
782 |
// Log.Write(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + "Error Item : " + beforeItem.UID + ", Error stack : " + stack.UID + "\r\n"); |
|
783 |
// MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace + "\r\n", "ARS ID2", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
784 |
// } |
|
785 |
|
|
786 |
// return false; |
|
787 |
//} |
|
788 |
} |
|
789 |
|
|
790 |
List<string> endGroupIds = new List<string>(); |
|
791 |
foreach (var item in itemDic) |
|
792 |
{ |
|
793 |
if (endGroupIds.Contains(item.Value)) |
|
794 |
continue; |
|
795 |
endGroupIds.Add(item.Value); |
|
796 |
|
|
797 |
List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList(); |
|
798 |
if (groupItems.Find(x => x.ItemType == ItemType.Line) == null) |
|
799 |
{ |
|
800 |
foreach (var groupItem in groupItems) |
|
801 |
Items.Remove(groupItem); |
|
802 |
} |
|
803 |
else |
|
804 |
{ |
|
805 |
Group group = new Group(this); |
|
806 |
group.Items = groupItems; |
|
807 |
group.UID = item.Value; |
|
808 |
group.SortItems(); |
|
809 |
foreach (Item groupItem in groupItems) |
|
810 |
groupItem.Group = group; |
|
811 |
Groups.Add(group); |
|
812 |
} |
|
813 |
} |
|
814 |
|
|
815 |
#region HeaderSetting |
|
816 |
List<HeaderInfo> HeaderInfos = new List<HeaderInfo>(); |
|
817 |
DataTable dt = DB.SelectHeaderSetting(); |
|
818 |
foreach (DataRow row in dt.Rows) |
|
819 |
{ |
|
820 |
string groupID = row["GROUP_ID"].ToString(); |
|
821 |
string desc = row["DESCRIPTION"].ToString(); |
|
822 |
int index = Convert.ToInt32(row["INDEX"]); |
|
823 |
string name = row["NAME"].ToString(); |
|
824 |
|
|
825 |
HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID)); |
|
826 |
if (headerInfo == null) |
|
827 |
{ |
|
828 |
headerInfo = new HeaderInfo(groupID); |
|
829 |
headerInfo.Description = desc; |
|
830 |
HeaderInfos.Add(headerInfo); |
|
831 |
} |
|
832 |
|
|
833 |
|
|
834 |
headerInfo.HeaderItems.Add(new HeaderItem() |
|
835 |
{ |
|
836 |
Index = index, |
|
837 |
Name = name |
|
838 |
}); |
|
839 |
} |
|
840 |
|
|
841 |
|
|
842 |
foreach (HeaderInfo headerInfo in HeaderInfos) |
|
843 |
headerInfo.HeaderItems = headerInfo.HeaderItems.OrderByDescending(x => x.Index).ToList(); |
|
844 |
|
|
845 |
foreach (Group group in Groups) |
|
846 |
{ |
|
847 |
foreach (HeaderInfo header in HeaderInfos) |
|
848 |
{ |
|
849 |
if (group.Items.Count < header.HeaderItems.Count) |
|
850 |
{ |
|
851 |
continue; |
|
852 |
} |
|
853 |
|
|
854 |
bool found = true; |
|
855 |
for (int i = 0; i < header.HeaderItems.Count; i++) |
|
856 |
{ |
|
857 |
if (!header.HeaderItems[header.HeaderItems.Count - 1 - i].Name.Equals(group.Items[i].Name)) |
|
858 |
{ |
|
859 |
found = false; |
|
860 |
break; |
|
861 |
} |
|
862 |
} |
|
863 |
if (found) |
|
864 |
{ |
|
865 |
found = false; |
|
866 |
List<Item> branches = new List<Item>(); |
|
867 |
//for (int i = 0; i < header.HeaderItems.Count; i++) |
|
868 |
//{ |
|
869 |
// if (group.Items[i].ItemType == ItemType.Line) |
|
870 |
// { |
|
871 |
foreach (var _line in group.Items.Where(x => x.ItemType == ItemType.Line)) |
|
872 |
{ |
|
873 |
branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList(); |
|
874 |
if (branches.Count > 0) |
|
875 |
{ |
|
876 |
found = true; |
|
877 |
break; |
|
878 |
} |
|
879 |
|
|
880 |
if (found) |
|
881 |
break; |
|
882 |
} |
|
883 |
// } |
|
884 |
//} |
|
885 |
|
|
886 |
if (found) |
|
887 |
{ |
|
888 |
for (int i = 0; i < header.HeaderItems.Count; i++) |
|
889 |
{ |
|
890 |
group.Items[i].SubItemType = SubItemType.Header; |
|
891 |
} |
|
892 |
} |
|
893 |
} |
|
894 |
|
|
895 |
found = true; |
|
896 |
for (int i = 0; i < header.HeaderItems.Count; i++) |
|
897 |
{ |
|
898 |
if (!header.HeaderItems[i].Name.Equals(group.Items[group.Items.Count - header.HeaderItems.Count + i].Name)) |
|
899 |
{ |
|
900 |
found = false; |
|
901 |
break; |
|
902 |
} |
|
903 |
} |
|
904 |
if (found) |
|
905 |
{ |
|
906 |
found = false; |
|
907 |
List<Item> branches = new List<Item>(); |
|
908 |
//for (int i = 0; i < header.HeaderItems.Count; i++) |
|
909 |
//{ |
|
910 |
// if (group.Items[group.Items.Count - 1 - i].ItemType == ItemType.Line) |
|
911 |
// { |
|
912 |
|
|
913 |
foreach (var _line in group.Items.Where(x => x.ItemType == ItemType.Line)) |
|
914 |
{ |
|
915 |
branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList(); |
|
916 |
if (branches.Count > 0) |
|
917 |
{ |
|
918 |
found = true; |
|
919 |
break; |
|
920 |
} |
|
921 |
|
|
922 |
if (found) |
|
923 |
break; |
|
924 |
} |
|
925 |
// } |
|
926 |
//} |
|
927 |
|
|
928 |
if (found) |
|
929 |
{ |
|
930 |
for (int i = 0; i < header.HeaderItems.Count; i++) |
|
931 |
{ |
|
932 |
group.Items[group.Items.Count - 1 - i].SubItemType = SubItemType.Header; |
|
933 |
} |
|
934 |
} |
|
935 |
} |
|
936 |
} |
|
937 |
} |
|
938 |
|
|
939 |
#endregion |
|
940 |
|
|
941 |
int GetConnectedItemCount(Item item) |
|
942 |
{ |
|
943 |
return item.Relations.FindAll(x => x.Item != null).Count; |
|
944 |
} |
|
945 |
|
|
946 |
List<Item> GetConnectedLines(Item item) |
|
947 |
{ |
|
948 |
List<Item> result = new List<Item>(); |
|
949 |
List<Item> end = new List<Item>(); |
|
950 |
Stack<Item> stacks = new Stack<Item>(); |
|
951 |
stacks.Push(item); |
|
952 |
while (stacks.Count > 0) |
|
953 |
{ |
|
954 |
Item stack = stacks.Pop(); |
|
955 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
|
956 |
continue; |
|
957 |
end.Add(stack); |
|
958 |
|
|
959 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
960 |
foreach (Relation relation in relations) |
|
961 |
stacks.Push(relation.Item); |
|
962 |
|
|
963 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
|
964 |
foreach (Relation relation in relations) |
|
965 |
{ |
|
966 |
result.Add(relation.Item); |
|
967 |
end.Add(relation.Item); |
|
968 |
} |
|
969 |
} |
|
970 |
|
|
971 |
return result; |
|
972 |
} |
|
973 |
|
|
974 |
List<Item> GetConnectedForwardLines(Item item) |
|
975 |
{ |
|
976 |
List<Item> result = new List<Item>(); |
|
977 |
List<Item> end = new List<Item>(); |
|
978 |
Stack<Item> stacks = new Stack<Item>(); |
|
979 |
stacks.Push(item); |
|
980 |
while (stacks.Count > 0) |
|
981 |
{ |
|
982 |
Item stack = stacks.Pop(); |
|
983 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
|
984 |
continue; |
|
985 |
end.Add(stack); |
|
986 |
|
|
987 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
988 |
foreach (Relation relation in relations) |
|
989 |
stacks.Push(relation.Item); |
|
990 |
|
|
991 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
|
992 |
foreach (Relation relation in relations) |
|
993 |
{ |
|
994 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0)) |
|
995 |
result.Add(relation.Item); |
|
996 |
|
|
997 |
end.Add(relation.Item); |
|
998 |
} |
|
999 |
} |
|
1000 |
|
|
1001 |
return result; |
|
1002 |
} |
|
1003 |
|
|
1004 |
List<Item> GetConnectedBackwardLines(Item item) |
|
1005 |
{ |
|
1006 |
List<Item> result = new List<Item>(); |
|
1007 |
List<Item> end = new List<Item>(); |
|
1008 |
Stack<Item> stacks = new Stack<Item>(); |
|
1009 |
stacks.Push(item); |
|
1010 |
while (stacks.Count > 0) |
|
1011 |
{ |
|
1012 |
Item stack = stacks.Pop(); |
|
1013 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
|
1014 |
continue; |
|
1015 |
end.Add(stack); |
|
1016 |
|
|
1017 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
1018 |
foreach (Relation relation in relations) |
|
1019 |
stacks.Push(relation.Item); |
|
1020 |
|
|
1021 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
|
1022 |
foreach (Relation relation in relations) |
|
1023 |
{ |
|
1024 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1)) |
|
1025 |
result.Add(relation.Item); |
|
1026 |
|
|
1027 |
end.Add(relation.Item); |
|
1028 |
} |
|
1029 |
} |
|
1030 |
|
|
1031 |
return result; |
|
1032 |
} |
|
1033 |
|
|
1034 |
double InchToNumber(string inchString) |
|
1035 |
{ |
|
1036 |
string[] inches = inchString.Replace("\"", "").Split('-'); |
|
1037 |
double number = 0; |
|
1038 |
foreach (string inch in inches) |
|
1039 |
{ |
|
1040 |
if (!inch.Contains('/')) |
|
1041 |
{ |
|
1042 |
number += Convert.ToDouble(inch); |
|
1043 |
} |
|
1044 |
else |
|
1045 |
{ |
|
1046 |
string[] _inches = inch.Split('/'); |
|
1047 |
number += Convert.ToDouble(_inches[0]) / Convert.ToDouble(_inches[1]); |
|
1048 |
} |
|
1049 |
} |
|
1050 |
|
|
1051 |
return number; |
|
1052 |
} |
|
1053 |
|
|
1054 |
Item GetConnectedMatchedSymbol(Item startItem, Item preItem, Item endItem) |
|
1055 |
{ |
|
1056 |
List<Item> connItem = GetConnectedSymbols(startItem).Where(w => w != preItem).ToList(); |
|
1057 |
if (connItem.Count != 0 && connItem[0] == endItem) |
|
1058 |
{ |
|
1059 |
return startItem; |
|
1060 |
} |
|
1061 |
else if (connItem.Count != 0) |
|
1062 |
{ |
|
1063 |
return GetConnectedMatchedSymbol(connItem[0], startItem, endItem); |
|
1064 |
} |
|
1065 |
|
|
1066 |
return null; |
|
1067 |
} |
|
1068 |
|
|
1069 |
Item GetConnectedMatchedLIne(Item startItem, Item preItem) |
|
1070 |
{ |
|
1071 |
if (startItem.ItemType == ItemType.Line) |
|
1072 |
return startItem; |
|
1073 |
|
|
1074 |
List<Item> connItem = GetConnectedLines(startItem).ToList(); |
|
1075 |
if (connItem.Count != 0) |
|
1076 |
{ |
|
1077 |
return connItem[0]; |
|
1078 |
} |
|
1079 |
else if (connItem.Count == 0) |
|
1080 |
{ |
|
1081 |
List<Item> _connItem = GetConnectedSymbols(startItem).Where(w => w != preItem).ToList(); |
|
1082 |
if (_connItem.Count == 0) |
|
1083 |
{ |
|
1084 |
return GetConnectedMatchedLIne(_connItem[0], startItem); |
|
1085 |
} |
|
1086 |
return null; |
|
1087 |
} |
|
1088 |
|
|
1089 |
return null; |
|
1090 |
} |
|
1091 |
|
|
1092 |
List<Item> GetConnectedSymbols(Item item) |
|
1093 |
{ |
|
1094 |
List<Item> result = new List<Item>(); |
|
1095 |
List<Item> end = new List<Item>(); |
|
1096 |
Stack<Item> stacks = new Stack<Item>(); |
|
1097 |
stacks.Push(item); |
|
1098 |
while (stacks.Count > 0) |
|
1099 |
{ |
|
1100 |
Item stack = stacks.Pop(); |
|
1101 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
|
1102 |
continue; |
|
1103 |
end.Add(stack); |
|
1104 |
result.Add(stack); |
|
1105 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
|
1106 |
foreach (Relation relation in relations) |
|
1107 |
stacks.Push(relation.Item); |
|
1108 |
} |
|
1109 |
|
|
1110 |
return result; |
|
1111 |
} |
|
1112 |
|
|
1113 |
void ChangeGroupID(string from, string to) |
|
1114 |
{ |
|
1115 |
if (from.Equals(to)) |
|
1116 |
return; |
|
1117 |
|
|
1118 |
List<Item> changeItems = new List<Item>(); |
|
1119 |
foreach (var _item in itemDic) |
|
1120 |
if (_item.Value.Equals(from)) |
|
1121 |
changeItems.Add(_item.Key); |
|
1122 |
foreach (var _item in changeItems) |
|
1123 |
itemDic[_item] = to; |
|
1124 |
} |
|
1125 |
|
|
1126 |
bool IsConnected(Item item1, Item item2) |
|
1127 |
{ |
|
1128 |
if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
|
1129 |
item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
|
1130 |
return true; |
|
1131 |
else |
|
1132 |
return false; |
|
1133 |
} |
|
1134 |
|
|
1135 |
bool IsSameRun(Item item1, Item item2) |
|
1136 |
{ |
|
1137 |
return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false; |
|
1138 |
} |
|
1139 |
|
|
1140 |
bool IsSameOwner(Item item1, Item item2) |
|
1141 |
{ |
|
1142 |
return !string.IsNullOrEmpty(item1.Owner) && !string.IsNullOrEmpty(item2.Owner) && item1.Owner == item2.Owner ? true : false; |
|
1143 |
} |
|
1144 |
} |
|
1145 |
|
|
1146 |
|
|
1147 |
/* 구버전 |
|
242 | 1148 |
private void SetGroup() |
243 | 1149 |
{ |
244 | 1150 |
List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
... | ... | |
828 | 1734 |
return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false; |
829 | 1735 |
} |
830 | 1736 |
} |
1737 |
|
|
1738 |
*/ |
|
1739 |
|
|
1740 |
private double StringToNumber(string inchString) |
|
1741 |
{ |
|
1742 |
double number = 0; |
|
1743 |
|
|
1744 |
if (string.IsNullOrEmpty(inchString) || inchString == "None") |
|
1745 |
return 0; |
|
1746 |
|
|
1747 |
try |
|
1748 |
{ |
|
1749 |
string[] inches = inchString.Replace("\"", "").Split('-'); |
|
1750 |
foreach (string inch in inches) |
|
1751 |
{ |
|
1752 |
if (!inch.Contains('/')) |
|
1753 |
{ |
|
1754 |
number += Convert.ToDouble(inch); |
|
1755 |
} |
|
1756 |
else |
|
1757 |
{ |
|
1758 |
string[] _inches = inch.Split('/'); |
|
1759 |
number += Convert.ToDouble(_inches[0]) / Convert.ToDouble(_inches[1]); |
|
1760 |
} |
|
1761 |
} |
|
1762 |
} |
|
1763 |
catch (Exception ex) |
|
1764 |
{ |
|
1765 |
return 0; |
|
1766 |
} |
|
1767 |
|
|
1768 |
return number; |
|
1769 |
} |
|
1770 |
|
|
831 | 1771 |
private void RemoveItems() |
832 | 1772 |
{ |
833 | 1773 |
List<Item> removeItems = new List<Item>(); |
내보내기 Unified diff