프로젝트

일반

사용자정보

개정판 335b7a24

ID335b7a245e0cf6a23f082212f90455fc144e275d
상위 30a9ffce
하위 cf127e54

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #000 : add Branch Logic and Line Join Logic

Change-Id: I7fcee5115816a1d1d1b218321b40a2670fa6358b

차이점 보기:

DTI_PID/SPPIDConverter/AutoModeling.cs
30 30
        Ingr.RAD2D.Application radApp;
31 31
        SPPID_Document document;
32 32

  
33
        Dictionary<Line, List<Line>> BranchLines = new Dictionary<Line, List<Line>>();
34
        List<Tuple<string, Line, Line>> BranchLines2 = new List<Tuple<string, Line, Line>>();
33 35
        public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp)
34 36
        {
35 37
            this.document = document;
......
84 86
                        LineModelingByRun(run);
85 87
                    }
86 88
                }
89

  
90
                foreach (var item in BranchLines2)
91
                {
92
                    BranchLineModeling(item);
93
                }
94

  
95
                foreach (LineNumber lineNumber in document.LINENUMBERS)
96
                {
97

  
98
                    foreach (LineRun run in lineNumber.RUNS)
99
                    {
100
                        JoinRunLine(run);
101
                    }
102
                }
103

  
104
                foreach (TrimLine trimLine in document.TRIMLINES)
105
                {
106
                    foreach (LineRun run in trimLine.RUNS)
107
                    {
108
                        JoinRunLine(run);
109
                    }
110
                }
87 111
            }
88 112
            catch (Exception ex)
89 113
            {
......
217 241
            }
218 242
        }
219 243

  
220

  
221 244
        private void TestSource()
222 245
        {
223 246

  
......
301 324
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
302 325
            {
303 326
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
304
                //SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, targetSymbol.SPPID.ORIGINAL_X, targetSymbol.SPPID.ORIGINAL_Y);
305
                //double prevX = _TargetItem.get_XCoordinate();
306
                //double prevY = _TargetItem.get_YCoordinate();
307
                //if (slopeType == SlopeType.HORIZONTAL)
308
                //    y = prevY;
309
                //else if (slopeType == SlopeType.VERTICAL)
310
                //    x = prevX;
311

  
312 327
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
313 328
                ReleaseCOMObjects(_TargetItem);
314 329
            }
......
369 384

  
370 385
        private void LineModeling(List<Line> lines)
371 386
        {
372
            object DrwingID = "0";
373
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME, ref DrwingID);
387
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
374 388
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
375 389
            LMSymbol _LMSymbol1 = null;
376 390
            LMSymbol _LMSymbol2 = null;
......
378 392
            LMConnector targetConnector1 = null;
379 393
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
380 394
            LMConnector targetConnector2 = null;
395

  
396
            Line startBranchLine = null;
397
            Line endBranchLine = null;
398

  
381 399
            for (int i = 0; i < lines.Count; i++)
382 400
            {
383 401
                Line line = lines[i];
......
393 411
                        else
394 412
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
395 413
                    }
396
                    else if (connItem != null && connItem.GetType() == typeof(Line))
414
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
397 415
                    {
398 416
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
399 417
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
......
401 419
                        if (targetConnector1 != null)
402 420
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
403 421
                        else
422
                        {
423
                            if (!BranchLines.ContainsKey(line))
424
                                BranchLines.Add(line, new List<Line>());
425
                            BranchLines[line].Add(connItem as Line);
426
                            startBranchLine = connItem as Line;
404 427
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
428
                        }
405 429
                    }
406 430
                    else
407 431
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
......
424 448
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
425 449
                            
426 450
                    }
427
                    else if (connItem != null && connItem.GetType() == typeof(Line))
451
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
428 452
                    {
429 453
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
430 454
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
......
432 456
                        if (targetConnector2 != null)
433 457
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
434 458
                        else
459
                        {
460
                            if (!BranchLines.ContainsKey(line))
461
                                BranchLines.Add(line, new List<Line>());
462
                            BranchLines[line].Add(connItem as Line);
463
                            endBranchLine = connItem as Line;
435 464
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
465
                        }
436 466
                    }
437 467
                    else
438 468
                    {
......
442 472
            }
443 473

  
444 474
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
475

  
445 476
            if (_lMConnector != null)
446 477
            {
447 478
                foreach (var line in lines)
448 479
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
449 480
                _lMConnector.Commit();
481
                if (startBranchLine != null || endBranchLine != null)
482
                {
483
                    BranchLines2.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
484
                }
450 485
            }
451 486

  
452 487

  
......
468 503
            ReleaseCOMObjects(_LMAItem);
469 504
        }
470 505

  
506
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
507
        {
508
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
509
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
510

  
511
            LMConnector _LMConnectorStart = null;
512
            LMConnector _LMConnectorEnd = null;
513
            double lengthStart = double.MaxValue;
514
            double lengthEnd = double.MaxValue;
515
            List<double[]> startPoints = new List<double[]>();
516
            List<double[]> endPoints = new List<double[]>();
517

  
518
            foreach (var item in connectorVertices)
519
            {
520
                foreach (var point in item.Value)
521
                {
522
                    // Start Point가 Branch
523
                    if (branch.Item2 != null)
524
                    {
525
                        Line targetLine = branch.Item2;
526
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
527
                        if (lengthStart > distance)
528
                        {
529
                            _LMConnectorStart = item.Key;
530
                            lengthStart = distance;
531
                            startPoints = item.Value;
532
                        }
533
                    }
534
                    // End Point가 Branch
535
                    if (branch.Item3 != null)
536
                    {
537
                        Line targetLine = branch.Item3;
538
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
539
                        if (lengthEnd > distance)
540
                        {
541
                            _LMConnectorEnd = item.Key;
542
                            lengthEnd = distance;
543
                            endPoints = item.Value;
544
                        }
545
                    }
546
                }
547
            }
548
            #region Branch가 양쪽 전부일 때
549
            if (_LMConnectorStart != null && _LMConnectorStart == _LMConnectorEnd)
550
            {
551
                _placement.PIDRemovePlacement(_LMConnectorStart.AsLMRepresentation());
552

  
553
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
554
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
555

  
556
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
557
                LMConnector startTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
558
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
559
                LMConnector endTargetConnector = FindTargetLMConnector(endConnectorVertices,
560
                   startPoints[startPoints.Count - 1][0],
561
                   startPoints[startPoints.Count - 1][1],
562
                   startPoints[startPoints.Count - 2][0],
563
                   startPoints[startPoints.Count - 2][1]);
564

  
565
                for (int i = 0; i < startPoints.Count; i++)
566
                {
567
                    double[] point = startPoints[i];
568
                    if (i == 0)
569
                        placeRunInputs.AddConnectorTarget(startTargetConnector, point[0], point[1]);
570
                    else if (i == startPoints.Count - 1)
571
                        placeRunInputs.AddConnectorTarget(endTargetConnector, point[0], point[1]);
572
                    else
573
                        placeRunInputs.AddPoint(point[0], point[1]);
574
                }
575

  
576
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
577
                if (_LMConnector != null)
578
                {
579
                    _LMConnector.Commit();
580
                    foreach (var item in lines)
581
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
582
                }
583

  
584
                foreach (var item in startConnectorVertices)
585
                    ReleaseCOMObjects(item.Key);
586
                foreach (var item in endConnectorVertices)
587
                    ReleaseCOMObjects(item.Key);
588
                ReleaseCOMObjects(placeRunInputs);
589
                ReleaseCOMObjects(_LMAItem);
590
                ReleaseCOMObjects(_LMConnector);
591
            }
592
            #endregion
593
            #region 한쪽만 Branch 
594
            else
595
            {
596
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
597
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
598

  
599
                // Branch 시작 Connector
600
                if (_LMConnectorStart != null)
601
                {
602
                    LMConnector endTargetConnector = null;
603
                    LMSymbol endTargetSymbol = null;
604
                    // Branch 반대편이 Line
605
                    foreach (var item in connectorVertices)
606
                    {
607
                        if (item.Key == _LMConnectorStart)
608
                            continue;
609

  
610
                        if (item.Key.ConnectItem1SymbolID == _LMConnectorStart.ConnectItem2SymbolID || 
611
                            item.Key.ConnectItem2SymbolID == _LMConnectorStart.ConnectItem2SymbolID)
612
                        {
613
                            endTargetConnector = item.Key;
614
                            break;
615
                        }
616
                    }
617
                    // Branch 반대편이 Symbol
618
                    if (endTargetConnector == null)
619
                    {
620
                        foreach (var line in lines)
621
                        {
622
                            foreach (var connector in line.CONNECTORS)
623
                            {
624
                                Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
625
                                if (symbol != null)
626
                                {
627
                                    endTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
628
                                    break;
629
                                }
630
                            }
631
                        }
632
                    }
633

  
634
                    _placement.PIDRemovePlacement(_LMConnectorStart.AsLMRepresentation());
635

  
636
                    Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
637
                    LMConnector startTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
638

  
639
                    for (int i = 0; i < startPoints.Count; i++)
640
                    {
641
                        double[] point = startPoints[i];
642
                        if (i == 0)
643
                            placeRunInputs.AddConnectorTarget(startTargetConnector, point[0], point[1]);
644
                        else if (i == startPoints.Count - 1)
645
                        {
646
                            if (endTargetConnector != null)
647
                                placeRunInputs.AddConnectorTarget(endTargetConnector, point[0], point[1]);
648
                            else if (endTargetSymbol != null)
649
                                placeRunInputs.AddSymbolTarget(endTargetSymbol, point[0], point[1]);
650
                            else
651
                                placeRunInputs.AddPoint(point[0], point[1]);
652
                        }
653
                        else
654
                            placeRunInputs.AddPoint(point[0], point[1]);
655
                    }
656

  
657
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
658
                    if (_LMConnector != null )
659
                    {
660
                        if (endTargetConnector != null)
661
                        {
662
                            JoinPipeRun(_LMConnector.ModelItemID, endTargetConnector.ModelItemID);
663
                        }
664
                        else
665
                        {
666
                            foreach (var item in lines)
667
                                item.SPPID.ModelItemId = _LMConnector.ModelItemID;
668
                        }
669

  
670
                        _LMConnector.Commit();
671
                        ReleaseCOMObjects(_LMConnector);
672
                    }
673

  
674
                    if (endTargetConnector != null)
675
                        ReleaseCOMObjects(endTargetConnector);
676
                    if (endTargetSymbol != null)
677
                        ReleaseCOMObjects(endTargetSymbol);
678
                    foreach (var item in startConnectorVertices)
679
                        ReleaseCOMObjects(item.Key);
680

  
681
                }
682
                // Branch 끝 Connector
683
                if (_LMConnectorEnd != null)
684
                {
685
                    LMConnector startTargetConnector = null;
686
                    LMSymbol startTargetSymbol = null;
687
                    // Branch 반대편이 Line
688
                    foreach (var item in connectorVertices)
689
                    {
690
                        if (item.Key == _LMConnectorEnd)
691
                            continue;
692

  
693
                        if (item.Key.ConnectItem1SymbolID == _LMConnectorEnd.ConnectItem1SymbolID ||
694
                            item.Key.ConnectItem2SymbolID == _LMConnectorEnd.ConnectItem1SymbolID)
695
                        {
696
                            startTargetConnector = item.Key;
697
                            break;
698
                        }
699
                    }
700
                    // Branch 반대편이 Symbol
701
                    if (startTargetConnector == null)
702
                    {
703
                        foreach (var line in lines)
704
                        {
705
                            foreach (var connector in line.CONNECTORS)
706
                            {
707
                                Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
708
                                if (symbol != null)
709
                                {
710
                                    startTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
711
                                    break;
712
                                }
713
                            }
714
                        }
715
                    }
716

  
717
                    _placement.PIDRemovePlacement(_LMConnectorEnd.AsLMRepresentation());
718

  
719
                    Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
720
                    LMConnector endTargetConnector = FindTargetLMConnector(startConnectorVertices, 
721
                        endPoints[endPoints.Count - 1][0], 
722
                        endPoints[endPoints.Count - 1][1], 
723
                        endPoints[endPoints.Count - 2][0], 
724
                        endPoints[endPoints.Count - 2][1]);
725

  
726
                    for (int i = 0; i < endPoints.Count; i++)
727
                    {
728
                        double[] point = endPoints[i];
729
                        if (i == 0)
730
                        {
731
                            if (startTargetConnector != null)
732
                                placeRunInputs.AddConnectorTarget(startTargetConnector, point[0], point[1]);
733
                            else if (startTargetSymbol != null)
734
                                placeRunInputs.AddSymbolTarget(startTargetSymbol, point[0], point[1]);
735
                            else
736
                                placeRunInputs.AddPoint(point[0], point[1]);
737
                        }
738
                        else if (i == endPoints.Count - 1)
739
                        {
740
                            placeRunInputs.AddConnectorTarget(endTargetConnector, point[0], point[1]);
741
                        }
742
                        else
743
                            placeRunInputs.AddPoint(point[0], point[1]);
744
                    }
745

  
746
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
747
                    if (_LMConnector != null)
748
                    {
749
                        if (startTargetConnector != null)
750
                        {
751
                            JoinPipeRun(_LMConnector.ModelItemID, startTargetConnector.ModelItemID);
752
                        }
753
                        else
754
                        {
755
                            foreach (var item in lines)
756
                                item.SPPID.ModelItemId = _LMConnector.ModelItemID;
757
                        }
758

  
759
                        _LMConnector.Commit();
760
                        ReleaseCOMObjects(_LMConnector);
761
                    }
762

  
763
                    if (startTargetConnector != null)
764
                        ReleaseCOMObjects(startTargetConnector);
765
                    if (startTargetSymbol != null)
766
                        ReleaseCOMObjects(startTargetSymbol);
767
                    foreach (var item in startConnectorVertices)
768
                        ReleaseCOMObjects(item.Key);
769
                }
770

  
771
                ReleaseCOMObjects(_LMAItem);
772
                ReleaseCOMObjects(placeRunInputs);
773
            }
774
            #endregion
775

  
776
            if (_LMConnectorStart != null)
777
                ReleaseCOMObjects(_LMConnectorStart);
778
            if (_LMConnectorEnd != null)
779
                ReleaseCOMObjects(_LMConnectorEnd);
780
            foreach (var item in connectorVertices)
781
                ReleaseCOMObjects(item.Key);
782

  
783

  
784

  
785
            //if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
786
            //{
787

  
788

  
789

  
790
            //}
791
        }
792

  
793
        private void BranchLineModeling(Line line, List<Line> targetLine)
794
        {
795
            Line tempLine1 = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM) as Line;
796
            Line tempLine2 = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM) as Line;
797
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
798

  
799
            LMConnector _LMConnectorStart = null;
800
            LMConnector _LMConnectorEnd = null;
801
            double lengthStart = double.MaxValue;
802
            List<double[]> startPoint = new List<double[]>();
803
            double lengthEnd = double.MaxValue;
804
            List<double[]> endPoint = new List<double[]>();
805

  
806
            foreach (var item in connectorVertices)
807
            {
808
                foreach (var point in item.Value)
809
                {
810
                    double distance = SPPIDUtil.CalcPointToPointdDistance(line.SPPID.START_X, line.SPPID.START_Y, point[0], point[1]);
811
                    if (lengthStart > distance)
812
                    {
813
                        _LMConnectorStart = item.Key;
814
                        lengthStart = distance;
815
                        startPoint = item.Value;
816
                    }
817

  
818
                    distance = SPPIDUtil.CalcPointToPointdDistance(line.SPPID.END_X, line.SPPID.END_Y, point[0], point[1]);
819
                    if (lengthEnd > distance)
820
                    {
821
                        _LMConnectorEnd = item.Key;
822
                        lengthEnd = distance;
823
                        endPoint = item.Value;
824
                    }
825
                }
826
            }
827

  
828
            if (_LMConnectorStart == _LMConnectorEnd)
829
            {
830
                _placement.PIDRemovePlacement(_LMConnectorStart.AsLMRepresentation());
831

  
832
                _LMAItem _LMAItem = _placement.PIDCreateItem(line.SPPID.MAPPINGNAME);
833
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
834

  
835
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(tempLine1.SPPID.ModelItemId);
836
                LMConnector startTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoint[0][0], startPoint[0][1], startPoint[1][0], startPoint[1][1]);
837
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(tempLine2.SPPID.ModelItemId);
838
                LMConnector endTargetConnector = FindTargetLMConnector(endConnectorVertices, 
839
                    startPoint[startPoint.Count - 1][0], 
840
                    startPoint[startPoint.Count - 1][1], 
841
                    startPoint[startPoint.Count - 2][0], 
842
                    startPoint[startPoint.Count - 2][1]);
843

  
844
                for (int i = 0; i < startPoint.Count; i++)
845
                {
846
                    double[] point = startPoint[i];
847
                    if (i == 0)
848
                    {
849
                        placeRunInputs.AddConnectorTarget(startTargetConnector, point[0], point[1]);
850
                    }
851
                    else if (i == startPoint.Count - 1)
852
                    {
853
                        placeRunInputs.AddConnectorTarget(endTargetConnector, point[0], point[1]);
854
                    }
855
                    else
856
                    {
857
                        placeRunInputs.AddPoint(point[0], point[1]);
858
                    }
859
                }
860

  
861
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
862
            }
863
            else
864
            {
865

  
866
            }
867

  
868

  
869

  
870
            if (_LMConnectorStart != null)
871
                ReleaseCOMObjects(_LMConnectorStart);
872
            if (_LMConnectorEnd != null)
873
                ReleaseCOMObjects(_LMConnectorEnd);
874
            foreach (var item in connectorVertices)
875
                ReleaseCOMObjects(item.Key);
876

  
877

  
878

  
879
            //if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
880
            //{
881

  
882

  
883

  
884
            //}
885
        }
886

  
887
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
888
        {
889
            LMPipeRun run1 = dataSource.GetPipeRun(toModelItemId);
890
            LMPipeRun run2 = dataSource.GetPipeRun(fromModelItemId);
891
            // item2가 item1으로 조인
892
            try
893
            {
894
                _LMAItem item1 = run1.AsLMAItem();
895
                _LMAItem item2 = run2.AsLMAItem();
896

  
897
                _placement.PIDJoinRuns(ref item1, ref item2);
898
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
899
                foreach (var line in lines)
900
                    line.SPPID.ModelItemId = toModelItemId;
901

  
902
            }
903
            catch (Exception ex)
904
            {
905
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
906
            }
907
            finally
908
            {
909
                ReleaseCOMObjects(run1);
910
                ReleaseCOMObjects(run2);
911
            }
912
        }
913

  
914
        private void AutoJoinPipeRun(string modelItemId)
915
        {
916
            LMPipeRun run = dataSource.GetPipeRun(modelItemId);
917
            _LMAItem item = run.AsLMAItem();
918
            _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
919
        }
920

  
921
        private void JoinRunLine(LineRun run)
922
        {
923
            string modelItemId = string.Empty;
924
            foreach (var item in run.RUNITEMS)
925
            {
926
                if (item.GetType() == typeof(Line))
927
                {
928
                    Line line = item as Line;
929
                    if (modelItemId != line.SPPID.ModelItemId)
930
                    {
931
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
932
                        modelItemId = line.SPPID.ModelItemId;
933
                    }
934
                    //if (string.IsNullOrEmpty(modelItemId))
935
                    //{
936
                    //    modelItemId = line.SPPID.ModelItemId;
937
                    //}
938
                    //else if(modelItemId != line.SPPID.ModelItemId)
939
                    //{
940
                    //    JoinPipeRun(line.SPPID.ModelItemId, modelItemId);
941
                    //}
942
                }
943
            }
944
        }
945

  
471 946
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
472 947
        {
473 948
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
......
481 956
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
482 957
                        connectorVertices.Add(_LMConnector, new List<double[]>());
483 958
                        dynamic OID = rep.get_GraphicOID();
484
                        Ingr.RAD2D.DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
959
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
485 960
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
486 961
                        int verticesCount = lineStringGeometry.VertexCount;
487 962
                        double[] vertices = null;
......
491 966
                            double x = 0;
492 967
                            double y = 0;
493 968
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
494
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
969
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
495 970
                        }
496 971
                    }
497 972
                }
......
514 989
                    double[] point1 = points[i];
515 990
                    double[] point2 = points[i + 1];
516 991

  
992
                    double maxLineX = Math.Max(point1[0], point2[0]);
993
                    double minLineX = Math.Min(point1[0], point2[0]);
994
                    double maxLineY = Math.Max(point1[1], point2[1]);
995
                    double minLineY = Math.Min(point1[1], point2[1]);
996

  
997
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
998

  
517 999
                    // 두직선의 교차점
518 1000
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
519 1001
                    if (crossingPoint != null)
520 1002
                    {
521 1003
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
522
                        if (length > distance)
1004
                        if (length >= distance)
523 1005
                        {
524
                            targetConnector = item.Key;
525
                            length = distance;
1006
                            if (slope == SlopeType.Slope &&
1007
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
1008
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1009
                            {
1010
                                targetConnector = item.Key;
1011
                                length = distance;
1012
                            }
1013
                            else if (slope == SlopeType.HORIZONTAL &&
1014
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
1015
                            {
1016
                                targetConnector = item.Key;
1017
                                length = distance;
1018
                            }
1019
                            else if (slope == SlopeType.VERTICAL &&
1020
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1021
                            {
1022
                                targetConnector = item.Key;
1023
                                length = distance;
1024
                            }
526 1025
                        }
527 1026
                    }
528 1027
                }
DTI_PID/SPPIDConverter/Util/SPPIDUtil.cs
258 258

  
259 259
            return null;
260 260
        }
261
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
262
        {
263
            List<Line> lines = new List<Line>();
264
            foreach (Line item in document.LINES)
265
            {
266
                if (item.SPPID.ModelItemId == ModelItemId)
267
                    lines.Add(item);
268
            }
269

  
270
            return lines;
271
        }
261 272
        #endregion
262 273
    }
263 274
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)