프로젝트

일반

사용자정보

개정판 f28a350a

IDf28a350ac026a09613d87b54a96424396189ec22
상위 5d2d88ca
하위 04f515d0, 360fd516

백흠경이(가) 5년 이상 전에 추가함

issue #663: setCurrentPidSource method 제거로 인한 오류 수정

Change-Id: Ia7c67a83ae51228dee1d13344dc300a3f10302bd

차이점 보기:

DTI_PID/SPPIDConverter/AutoModeling.cs
88 88
                    Log.Write("Start Modeling");
89 89
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
90 90
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
91
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 20);
91
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 22);
92 92
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
93 93

  
94 94
                    // Equipment Modeling
......
121 121
                    RunInputSymbolAttribute();
122 122
                    // Input SpecBreak Attribute
123 123
                    RunInputSpecBreakAttribute();
124
                    // Input EndBreak Attribute
125
                    RunInputEndBreakAttribute();
124 126
                    // Label Symbol Modeling
125 127
                    RunLabelSymbolModeling();
128
                    // Correct Text
129
                    RunCorrectAssociationText();
126 130

  
127 131
                    // Result Logging
128 132
                    document.CheckModelingResult();
......
264 268
                    Log.Write("UID : " + BranchLines[0].UID);
265 269
                    Log.Write(ex.Message);
266 270
                    Log.Write(ex.StackTrace);
267
                    break;
271
                    BranchLines.Remove(BranchLines[0]);
268 272
                }
269 273
            }
270 274

  
......
537 541
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1");
538 542
            foreach (var line in document.LINES)
539 543
            {
544
                Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(line.SPPID.ModelItemId, false);
545
                List<List<double[]>> result = new List<List<double[]>>();
546
                foreach (var item in vertices)
547
                {
548
                    ReleaseCOMObjects(item.Key);
549
                    result.Add(item.Value);
550
                }
551
                line.SPPID.Vertices = result;
552
                vertices = null;
553
            }
554

  
555
            foreach (var line in document.LINES)
556
            {
540 557
                foreach (var connector in line.CONNECTORS)
541 558
                {
542 559
                    if (connector.ConnectedObject != null &&
......
789 806
        {
790 807
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
791 808
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
792
            List<Text> correctList = new List<Text>();
809
            SortText(document.TEXTINFOS);
793 810
            foreach (var item in document.TEXTINFOS)
794 811
                try
795 812
                {
796
                    TextModeling(item, correctList);
797
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
798
                }
799
                catch (Exception ex)
800
                {
801
                    Log.Write("Error in TextModeling");
802
                    Log.Write("UID : " + item.UID);
803
                    Log.Write(ex.Message);
804
                    Log.Write(ex.StackTrace);
805
                }
806

  
807
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
808
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Text");
809
            SortText(correctList);
810
            List<Text> endList = new List<Text>();
811
            if (correctList.Count > 0)
812
                endList.Add(correctList[0]);
813
            foreach (var item in correctList)
814
                try
815
                {
816
                    if (!endList.Contains(item))
817
                        TextCorrectModeling(item, endList);
813
                    if (item.ASSOCIATION)
814
                        AssociationTextModeling(item);
815
                    else
816
                        NormalTextModeling(item);
818 817
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
819 818
                }
820 819
                catch (Exception ex)
......
864 863
        }
865 864
        private void RunInputSpecBreakAttribute()
866 865
        {
867
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
868
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
866
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
867
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set SpecBreak Attribute");
869 868
            foreach (var item in document.SpecBreaks)
870 869
                try
871 870
                {
......
880 879
                    Log.Write(ex.StackTrace);
881 880
                }
882 881
        }
882
        private void RunInputEndBreakAttribute()
883
        {
884
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
885
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set EndBreak Attribute");
886
            foreach (var item in document.EndBreaks)
887
                try
888
                {
889
                    InputEndBreakAttribute(item);
890
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
891
                }
892
                catch (Exception ex)
893
                {
894
                    Log.Write("Error in RunInputEndBreakAttribute");
895
                    Log.Write("UID : " + item.UID);
896
                    Log.Write(ex.Message);
897
                    Log.Write(ex.StackTrace);
898
                }
899
        }
883 900
        private void RunLabelSymbolModeling()
884 901
        {
885 902
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
......
898 915
                    Log.Write(ex.StackTrace);
899 916
                }
900 917
        }
901
        
918
        private void RunCorrectAssociationText()
919
        {
920
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count + document.LINENUMBERS.Count);
921
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Labels");
922
            List<Text> endTexts = new List<Text>();
923
            foreach (var item in document.TEXTINFOS)
924
            {
925
                try
926
                {
927
                    if (item.ASSOCIATION && !endTexts.Contains(item))
928
                        AssociationTextCorrectModeling(item, endTexts);
929
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
930
                }
931
                catch (Exception ex)
932
                {
933
                    Log.Write("Error in RunCorrectAssociationText");
934
                    Log.Write("UID : " + item.UID);
935
                    Log.Write(ex.Message);
936
                    Log.Write(ex.StackTrace);
937
                }
938
                
939
            }
940

  
941
            foreach (var item in document.LINENUMBERS)
942
            {
943
                try
944
                {
945
                    LineNumberCorrectModeling(item);
946
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
947
                }
948
                catch (Exception ex)
949
                {
950
                    Log.Write("Error in RunCorrectAssociationText");
951
                    Log.Write("UID : " + item.UID);
952
                    Log.Write(ex.Message);
953
                    Log.Write(ex.StackTrace);
954
                }
955
            }
956
        }
902 957
        /// <summary>
903 958
        /// 도면 생성 메서드
904 959
        /// </summary>
......
1400 1455
            ReleaseCOMObjects(_TargetItem);
1401 1456
        }
1402 1457

  
1403
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1458
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false)
1404 1459
        {
1405 1460
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1406 1461
            if (_TargetItem != null)
......
1410 1465
                double y1 = 0;
1411 1466
                double x2 = 0;
1412 1467
                double y2 = 0;
1413
                symbol2d.Range(out x1, out y1, out x2, out y2);
1414
                range = new double[] { x1, y1, x2, y2 };
1468
                if (!bForGraphic)
1469
                {
1470
                    symbol2d.Range(out x1, out y1, out x2, out y2);
1471
                    range = new double[] { x1, y1, x2, y2 };
1472
                }
1473
                else
1474
                {
1475
                    x1 = double.MaxValue;
1476
                    y1 = double.MaxValue;
1477
                    x2 = double.MinValue;
1478
                    y2 = double.MinValue;
1479
                    range = new double[] { x1, y1, x2, y2 };
1415 1480

  
1416
                foreach (var childSymbol in symbol.ChildSymbols)
1417
                    GetSPPIDChildSymbolRange(childSymbol, ref range);
1481
                    foreach (var item in symbol2d.DrawingObjects)
1482
                    {
1483
                        if (item.GetType() == typeof(Ingr.RAD2D.Line2d))
1484
                        {
1485
                            Ingr.RAD2D.Line2d rangeObject = item as Ingr.RAD2D.Line2d;
1486
                            if (rangeObject.Layer == "Default")
1487
                            {
1488
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1489
                                range = new double[] {
1490
                                Math.Min(x1, range[0]),
1491
                                Math.Min(y1, range[1]),
1492
                                Math.Max(x2, range[2]),
1493
                                Math.Max(y2, range[3])
1494
                            };
1495
                            }
1496
                        }
1497
                        else if (item.GetType() == typeof(Ingr.RAD2D.Circle2d))
1498
                        {
1499
                            Ingr.RAD2D.Circle2d rangeObject = item as Ingr.RAD2D.Circle2d;
1500
                            if (rangeObject.Layer == "Default")
1501
                            {
1502
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1503
                                range = new double[] {
1504
                                Math.Min(x1, range[0]),
1505
                                Math.Min(y1, range[1]),
1506
                                Math.Max(x2, range[2]),
1507
                                Math.Max(y2, range[3])
1508
                            };
1509
                            }
1510
                        }
1511
                        else if (item.GetType() == typeof(Ingr.RAD2D.Rectangle2d))
1512
                        {
1513
                            Ingr.RAD2D.Rectangle2d rangeObject = item as Ingr.RAD2D.Rectangle2d;
1514
                            if (rangeObject.Layer == "Default")
1515
                            {
1516
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1517
                                range = new double[] {
1518
                                Math.Min(x1, range[0]),
1519
                                Math.Min(y1, range[1]),
1520
                                Math.Max(x2, range[2]),
1521
                                Math.Max(y2, range[3])
1522
                            };
1523
                            }
1524
                        }
1525
                        else if (item.GetType() == typeof(Ingr.RAD2D.Arc2d))
1526
                        {
1527
                            Ingr.RAD2D.Arc2d rangeObject = item as Ingr.RAD2D.Arc2d;
1528
                            if (rangeObject.Layer == "Default")
1529
                            {
1530
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1531
                                range = new double[] {
1532
                                Math.Min(x1, range[0]),
1533
                                Math.Min(y1, range[1]),
1534
                                Math.Max(x2, range[2]),
1535
                                Math.Max(y2, range[3])
1536
                            };
1537
                            }
1538
                        }
1539
                    }
1540
                }
1418 1541

  
1542
                if (!bOnlySymbol)
1543
                {
1544
                    foreach (var childSymbol in symbol.ChildSymbols)
1545
                        GetSPPIDChildSymbolRange(childSymbol, ref range);
1546
                }
1419 1547
                ReleaseCOMObjects(_TargetItem);
1420 1548
            }
1421 1549
        }
......
1424 1552
        {
1425 1553
            if (labelPersist != null)
1426 1554
            {
1555
                double x1 = double.MaxValue;
1556
                double y1 = double.MaxValue;
1557
                double x2 = double.MinValue;
1558
                double y2 = double.MinValue;
1559
                range = new double[] { x1, y1, x2, y2 };
1560

  
1427 1561
                Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject;
1428
                if (dependency != null)
1562
                foreach (var item in dependency.DrawingObjects)
1429 1563
                {
1430
                    double x1 = 0;
1431
                    double y1 = 0;
1432
                    double x2 = 0;
1433
                    double y2 = 0;
1434
                    dependency.Range(out x1, out y1, out x2, out y2);
1435
                    range = new double[] { x1, y1, x2, y2 };
1564
                    Ingr.RAD2D.TextBox textBox = item as Ingr.RAD2D.TextBox;
1565
                    if (textBox != null)
1566
                    {
1567
                        if (dependency != null)
1568
                        {
1569
                            double tempX1;
1570
                            double tempY1;
1571
                            double tempX2;
1572
                            double tempY2;
1573
                            textBox.Range(out tempX1, out tempY1, out tempX2, out tempY2);
1574
                            x1 = Math.Min(x1, tempX1);
1575
                            y1 = Math.Min(y1, tempY1);
1576
                            x2 = Math.Max(x2, tempX2);
1577
                            y2 = Math.Max(y2, tempY2);
1578

  
1579
                            range = new double[] { x1, y1, x2, y2 };
1580
                        }
1581
                    }
1436 1582
                }
1583
                
1437 1584
            }
1438 1585
        }
1439 1586

  
......
2867 3014
                    if (slopeType == SlopeType.HORIZONTAL)
2868 3015
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2869 3016
                    else if (slopeType == SlopeType.VERTICAL)
2870
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
3017
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2871 3018
                }
2872 3019
                else if (targetLine != null)
2873 3020
                {
2874 3021
                    if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2875 3022
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2876 3023
                    else if (targetLine.SlopeType == SlopeType.VERTICAL)
2877
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
3024
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2878 3025
                }
2879 3026
                else if (connLine != null)
2880 3027
                {
2881 3028
                    if (connLine.SlopeType == SlopeType.HORIZONTAL)
2882 3029
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2883 3030
                    else if (connLine.SlopeType == SlopeType.VERTICAL)
2884
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
3031
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2885 3032
                }
2886 3033
            }
2887 3034
            else
......
3103 3250
                        attribute.set_Value("End 1 is upstream (Inlet)");
3104 3251
                }
3105 3252
                else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active")
3106
                    survivorId = null;
3253
                {
3254
                    int model1Cnt = GetConnectorCount(modelId1);
3255
                    int model2Cnt = GetConnectorCount(modelId2);
3256
                    if (model1Cnt == 0)
3257
                    {
3258
                        beforeID = modelItem1.Id;
3259
                        afterID = modelItem2.Id;
3260
                        survivorId = afterID;
3261
                        LMAAttribute attribute = modelItem2.Attributes["FlowDirection"];
3262
                        if (attribute != null)
3263
                            attribute.set_Value("End 1 is upstream (Inlet)");
3264
                    }
3265
                    else if (model2Cnt == 0)
3266
                    {
3267
                        beforeID = modelItem2.Id;
3268
                        afterID = modelItem1.Id;
3269
                        survivorId = afterID;
3270
                        LMAAttribute attribute = modelItem1.Attributes["FlowDirection"];
3271
                        if (attribute != null)
3272
                            attribute.set_Value("End 1 is upstream (Inlet)");
3273
                    }
3274
                    else
3275
                        survivorId = null;
3276
                }
3107 3277
                else
3108 3278
                {
3109 3279
                    Log.Write("잘못된 경우");
......
3227 3397
        /// </summary>
3228 3398
        /// <param name="modelId"></param>
3229 3399
        /// <returns></returns>
3230
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
3400
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true)
3231 3401
        {
3232 3402
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
3233 3403
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
......
3239 3409
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3240 3410
                    {
3241 3411
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
3412
                        if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength()))
3413
                        {
3414
                            ReleaseCOMObjects(_LMConnector);
3415
                            _LMConnector = null;
3416
                            continue;
3417
                        }
3242 3418
                        connectorVertices.Add(_LMConnector, new List<double[]>());
3243 3419
                        dynamic OID = rep.get_GraphicOID().ToString();
3244 3420
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
......
3637 3813
            return result;
3638 3814
        }
3639 3815

  
3816
        private int GetConnectorCount(string modelItemID)
3817
        {
3818
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3819
            int result = 0;
3820
            if (modelItem != null)
3821
            {
3822
                foreach (LMRepresentation rep in modelItem.Representations)
3823
                {
3824
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3825
                        result++;
3826
                    ReleaseCOMObjects(rep);
3827
                }
3828
                ReleaseCOMObjects(modelItem);
3829
            }
3830

  
3831
            return result;
3832
        }
3833

  
3640 3834
        public List<string> GetRepresentations(string modelItemID)
3641 3835
        {
3642 3836
            List<string> result = new List<string>(); ;
......
3671 3865
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3672 3866

  
3673 3867
                    Array points = new double[] { 0, x, y };
3868
                    lineNumber.SPPID.SPPID_X = x;
3869
                    lineNumber.SPPID.SPPID_Y = y;
3674 3870
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3675 3871

  
3676 3872
                    if (_LmLabelPresist != null)
......
3697 3893
                if (connectedLMConnector != null)
3698 3894
                {
3699 3895
                    Array points = new double[] { 0, x, y };
3896
                    lineNumber.SPPID.SPPID_X = x;
3897
                    lineNumber.SPPID.SPPID_Y = y;
3700 3898
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3701 3899

  
3702 3900
                    if (_LmLabelPresist != null)
......
3711 3909
                    ReleaseCOMObjects(item.Key);
3712 3910
            }
3713 3911
        }
3912
        private void LineNumberCorrectModeling(LineNumber lineNumber)
3913
        {
3914
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
3915
            if (line == null || line.SPPID.Vertices == null)
3916
                return;
3917

  
3918
            if (!string.IsNullOrEmpty(lineNumber.SPPID.RepresentationId))
3919
            {
3920
                LMLabelPersist removeLabel = dataSource.GetLabelPersist(lineNumber.SPPID.RepresentationId);
3921
                if (removeLabel != null)
3922
                {
3923
                    GridSetting gridSetting = GridSetting.GetInstance();
3924
                    double[] labelRange = null;
3925
                    GetSPPIDSymbolRange(removeLabel, ref labelRange);
3926
                    LMConnector connector = dataSource.GetConnector(removeLabel.RepresentationID);
3927
                    List<double[]> vertices = GetConnectorVertices(connector);
3928

  
3929
                    double[] resultStart = null;
3930
                    double[] resultEnd = null;
3931
                    double distance = double.MaxValue;
3932
                    for (int i = 0; i < vertices.Count - 1; i++)
3933
                    {
3934
                        double[] startPoint = vertices[i];
3935
                        double[] endPoint = vertices[i + 1];
3936
                        foreach (var item in line.SPPID.Vertices)
3937
                        {
3938
                            double[] lineStartPoint = item[0];
3939
                            double[] lineEndPoint = item[item.Count - 1];
3940

  
3941
                            double tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineStartPoint[0], lineStartPoint[1]) +
3942
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineEndPoint[0], lineEndPoint[1]);
3943
                            if (tempDistance < distance)
3944
                            {
3945
                                distance = tempDistance;
3946
                                resultStart = startPoint;
3947
                                resultEnd = endPoint;
3948
                            }
3949
                            tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineEndPoint[0], lineEndPoint[1]) +
3950
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineStartPoint[0], lineStartPoint[1]);
3951
                            if (tempDistance < distance)
3952
                            {
3953
                                distance = tempDistance;
3954
                                resultStart = startPoint;
3955
                                resultEnd = endPoint;
3956
                            }
3957
                        }
3958
                    }
3959

  
3960
                    if (resultStart != null && resultEnd != null)
3961
                    {
3962
                        SlopeType slope = SPPIDUtil.CalcSlope(resultStart[0], resultStart[1], resultEnd[0], resultEnd[1]);
3963
                        double lineStartX = 0;
3964
                        double lineStartY = 0;
3965
                        double lineEndX = 0;
3966
                        double lineEndY = 0;
3967
                        double lineNumberX = 0;
3968
                        double lineNumberY = 0;
3969
                        SPPIDUtil.ConvertPointBystring(line.STARTPOINT, ref lineStartX, ref lineStartY);
3970
                        SPPIDUtil.ConvertPointBystring(line.ENDPOINT, ref lineEndX, ref lineEndY);
3971

  
3972
                        double lineX = (lineStartX + lineEndX) / 2;
3973
                        double lineY = (lineStartY + lineEndY) / 2;
3974
                        lineNumberX = (lineNumber.X1 + lineNumber.X2) / 2;
3975
                        lineNumberY = (lineNumber.Y1 + lineNumber.Y2) / 2;
3976

  
3977
                        double SPPIDCenterX = (resultStart[0] + resultEnd[0]) / 2;
3978
                        double SPPIDCenterY = (resultStart[1] + resultEnd[1]) / 2;
3979
                        double labelCenterX = (labelRange[0] + labelRange[2]) / 2;
3980
                        double labelCenterY = (labelRange[1] + labelRange[3]) / 2;
3981

  
3982
                        double offsetX = 0;
3983
                        double offsetY = 0;
3984
                        if (slope == SlopeType.HORIZONTAL)
3985
                        {
3986
                            // Line Number 아래
3987
                            if (lineY < lineNumberY)
3988
                            {
3989
                                offsetX = labelCenterX - SPPIDCenterX;
3990
                                offsetY = labelRange[3] - SPPIDCenterY + gridSetting.Length;
3991
                                MoveLineNumber(lineNumber, offsetX, offsetY);
3992
                            }
3993
                            // Line Number 위
3994
                            else
3995
                            {
3996
                                offsetX = labelCenterX - SPPIDCenterX;
3997
                                offsetY = labelRange[1] - SPPIDCenterY - gridSetting.Length;
3998
                                MoveLineNumber(lineNumber, offsetX, offsetY);
3999
                            }
4000
                        }
4001
                        else if (slope == SlopeType.VERTICAL)
4002
                        {
4003
                            // Line Number 오르쪽
4004
                            if (lineX < lineNumberX)
4005
                            {
4006
                                offsetX = labelRange[0] - SPPIDCenterX - gridSetting.Length;
4007
                                offsetY = labelCenterY - SPPIDCenterY;
4008
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4009
                            }
4010
                            // Line Number 왼쪽
4011
                            else
4012
                            {
4013
                                offsetX = labelRange[2] - SPPIDCenterX + gridSetting.Length;
4014
                                offsetY = labelCenterY - SPPIDCenterY;
4015
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4016
                            }
4017
                        }
4018

  
4019
                        if (offsetY != 0 && offsetY != 0)
4020
                        {
4021
                            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
4022
                            Array points = new double[] { 0, lineNumber.SPPID.SPPID_X, lineNumber.SPPID.SPPID_Y };
4023
                            LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connector.AsLMRepresentation(), IsLeaderVisible: false);
4024

  
4025
                            if (_LmLabelPresist != null)
4026
                            {
4027
                                _LmLabelPresist.Commit();
4028
                                lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
4029
                            }
4030
                            ReleaseCOMObjects(_LmLabelPresist);
4031
                            _LmLabelPresist = null; 
4032
                        }
4033

  
4034
                        void MoveLineNumber(LineNumber moveLineNumber, double x, double y)
4035
                        {
4036
                            moveLineNumber.SPPID.SPPID_X = moveLineNumber.SPPID.SPPID_X - x;
4037
                            moveLineNumber.SPPID.SPPID_Y = moveLineNumber.SPPID.SPPID_Y - y;
4038
                        }
4039
                    }
4040

  
4041

  
4042
                    ReleaseCOMObjects(connector);
4043
                    connector = null;
4044
                }
4045

  
4046
                ReleaseCOMObjects(removeLabel);
4047
                removeLabel = null;
4048
            }
4049
        }
3714 4050
        /// <summary>
3715 4051
        /// Flow Mark Modeling
3716 4052
        /// </summary>
......
3843 4179
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3844 4180
                        if (_Attribute != null)
3845 4181
                        {
3846
                            object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
3847
                            if (associItem != null)
3848
                            {
3849
                                if (associItem.GetType() == typeof(Text))
3850
                                {
3851
                                    Text text = associItem as Text;
3852
                                    text.SPPID.RepresentationId = "Attribute";
3853
                                }
3854
                                else if (associItem.GetType() == typeof(Note))
3855
                                {
3856
                                    Note note = associItem as Note;
3857
                                    note.SPPID.RepresentationId = "Attribute";
3858
                                }
3859
                            }
4182
                            //object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
4183
                            //if (associItem != null)
4184
                            //{
4185
                            //    if (associItem.GetType() == typeof(Text))
4186
                            //    {
4187
                            //        Text text = associItem as Text;
4188
                            //        text.SPPID.RepresentationId = "Attribute";
4189
                            //    }
4190
                            //    else if (associItem.GetType() == typeof(Note))
4191
                            //    {
4192
                            //        Note note = associItem as Note;
4193
                            //        note.SPPID.RepresentationId = "Attribute";
4194
                            //    }
4195
                            //}
3860 4196
                            _Attribute.set_Value(item.VALUE);
3861 4197
                            // OPC 일경우 Attribute 저장
3862 4198
                            if (targetItem.GetType() == typeof(Symbol))
......
4076 4412
            #endregion
4077 4413
        }
4078 4414

  
4079
        /// <summary>
4080
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
4081
        /// </summary>
4082
        /// <param name="text"></param>
4083
        private void TextModeling(Text text, List<Text> correctList)
4415
        private void InputEndBreakAttribute(EndBreak endBreak)
4084 4416
        {
4085
            LMSymbol _LMSymbol = null;
4086
            LMConnector connectedLMConnector = null;
4087
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
4088
            if (text.ASSOCIATION)
4417
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
4418
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
4419

  
4420
            if ((ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Line)) ||
4421
                (ownerObj.GetType() == typeof(Line) && connectedItem.GetType() == typeof(Symbol)))
4089 4422
            {
4090
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
4091
                if (owner != null && owner.GetType() == typeof(Symbol))
4423
                LMLabelPersist labelPersist = dataSource.GetLabelPersist(endBreak.SPPID.RepresentationId);
4424
                if (labelPersist != null)
4092 4425
                {
4093
                    Symbol symbol = owner as Symbol;
4094
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4095
                    if (_LMSymbol != null)
4426
                    LMRepresentation representation = labelPersist.RepresentationObject;
4427
                    if (representation != null)
4096 4428
                    {
4097
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4098
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4429
                        LMConnector connector = dataSource.GetConnector(representation.Id);
4430
                        LMModelItem ZeroLengthModelItem = connector.ModelItemObject;
4431
                        string modelItemID = connector.ModelItemID;
4432
                        if (Convert.ToBoolean(connector.get_IsZeroLength()))
4099 4433
                        {
4100
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4101

  
4102
                            if (mapping != null)
4434
                            List<string> modelItemIDs = new List<string>();
4435
                            if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
4103 4436
                            {
4104
                                double x = 0;
4105
                                double y = 0;
4106

  
4107
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4108
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4109
                                Array array = new double[] { 0, x, y };
4110
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4111
                                if (_LMLabelPersist != null)
4437
                                LMSymbol symbol = connector.ConnectItem1SymbolObject;
4438
                                foreach (LMConnector item in symbol.Connect1Connectors)
4439
                                {
4440
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4441
                                        modelItemIDs.Add(item.ModelItemID);
4442
                                    ReleaseCOMObjects(item);
4443
                                }
4444
                                foreach (LMConnector item in symbol.Connect2Connectors)
4112 4445
                                {
4113
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4114
                                    _LMLabelPersist.Commit();
4115
                                    ReleaseCOMObjects(_LMLabelPersist);
4446
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4447
                                        modelItemIDs.Add(item.ModelItemID);
4448
                                    ReleaseCOMObjects(item);
4116 4449
                                }
4450
                                ReleaseCOMObjects(symbol);
4451
                                symbol = null;
4452
                            }
4453
                            else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
4454
                            {
4455
                                LMSymbol symbol = connector.ConnectItem2SymbolObject;
4456
                                foreach (LMConnector item in symbol.Connect1Connectors)
4457
                                {
4458
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4459
                                        modelItemIDs.Add(item.ModelItemID);
4460
                                    ReleaseCOMObjects(item);
4461
                                }
4462
                                foreach (LMConnector item in symbol.Connect2Connectors)
4463
                                {
4464
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4465
                                        modelItemIDs.Add(item.ModelItemID);
4466
                                    ReleaseCOMObjects(item);
4467
                                }
4468
                                ReleaseCOMObjects(symbol);
4469
                                symbol = null;
4117 4470
                            }
4118
                        }
4119
                    }
4120
                }
4121
                else if (owner != null && owner.GetType() == typeof(Line))
4122
                {
4123
                    Line line = owner as Line;
4124
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
4125
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
4126

  
4127
                    if (connectedLMConnector != null)
4128
                    {
4129
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4130
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4131
                        {
4132
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4133 4471

  
4134
                            if (mapping != null)
4472
                            modelItemIDs = modelItemIDs.Distinct().ToList();
4473
                            if (modelItemIDs.Count == 1)
4135 4474
                            {
4136
                                double x = 0;
4137
                                double y = 0;
4138
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4139
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4140
                                Array array = new double[] { 0, x, y };
4475
                                LMModelItem modelItem = dataSource.GetModelItem(modelItemIDs[0]);
4476
                                LMConnector onlyOne = GetLMConnectorOnlyOne(modelItem.Id);
4477
                                if (onlyOne != null && Convert.ToBoolean(onlyOne.get_IsZeroLength()))
4478
                                {
4479
                                    bool result = false;
4480
                                    foreach (LMLabelPersist loop in onlyOne.LabelPersists)
4481
                                    {
4482
                                        if (document.EndBreaks.Find(x => x.SPPID.RepresentationId == loop.RepresentationID) != null)
4483
                                            result = true;
4484
                                        ReleaseCOMObjects(loop);
4485
                                    }
4486

  
4487
                                    if (result)
4488
                                    {
4489
                                        object value = modelItem.Attributes["TagSequenceNo"].get_Value();
4490
                                        ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4491
                                        ZeroLengthModelItem.Commit();
4492
                                    }
4493
                                    else
4494
                                    {
4495
                                        List<string> loopModelItems = new List<string>();
4496
                                        if (onlyOne.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
4497
                                        {
4498
                                            LMSymbol _symbol = onlyOne.ConnectItem1SymbolObject;
4499
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
4500
                                            {
4501
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4502
                                                    loopModelItems.Add(loop.ModelItemID);
4503
                                                ReleaseCOMObjects(loop);
4504
                                            }
4505
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
4506
                                            {
4507
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4508
                                                    loopModelItems.Add(loop.ModelItemID);
4509
                                                ReleaseCOMObjects(loop);
4510
                                            }
4511
                                            ReleaseCOMObjects(_symbol);
4512
                                            _symbol = null;
4513
                                        }
4514
                                        else if (onlyOne.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
4515
                                        {
4516
                                            LMSymbol _symbol = onlyOne.ConnectItem2SymbolObject;
4517
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
4518
                                            {
4519
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4520
                                                    loopModelItems.Add(loop.ModelItemID);
4521
                                                ReleaseCOMObjects(loop);
4522
                                            }
4523
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
4524
                                            {
4525
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4526
                                                    loopModelItems.Add(loop.ModelItemID);
4527
                                                ReleaseCOMObjects(loop);
4528
                                            }
4529
                                            ReleaseCOMObjects(_symbol);
4530
                                            _symbol = null;
4531
                                        }
4141 4532

  
4142
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4143
                                if (_LMLabelPersist != null)
4533
                                        loopModelItems = loopModelItems.Distinct().ToList();
4534
                                        if (loopModelItems.Count == 1)
4535
                                        {
4536
                                            LMModelItem loopModelItem = dataSource.GetModelItem(loopModelItems[0]);
4537
                                            object value = loopModelItem.Attributes["TagSequenceNo"].get_Value();
4538
                                            modelItem.Attributes["TagSequenceNo"].set_Value(value);
4539
                                            modelItem.Commit();
4540
                                            ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4541
                                            ZeroLengthModelItem.Commit();
4542

  
4543
                                            ReleaseCOMObjects(loopModelItem);
4544
                                            loopModelItem = null;
4545
                                        }
4546
                                    }
4547
                                }
4548
                                else
4144 4549
                                {
4145
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4146
                                    _LMLabelPersist.Commit();
4147
                                    ReleaseCOMObjects(_LMLabelPersist);
4550
                                    object value = modelItem.Attributes["TagSequenceNo"].get_Value();
4551
                                    ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4552
                                    ZeroLengthModelItem.Commit();
4148 4553
                                }
4554
                                ReleaseCOMObjects(modelItem);
4555
                                modelItem = null;
4556
                                ReleaseCOMObjects(onlyOne);
4557
                                onlyOne = null;
4149 4558
                            }
4150 4559
                        }
4560
                        ReleaseCOMObjects(connector);
4561
                        connector = null;
4562
                        ReleaseCOMObjects(ZeroLengthModelItem);
4563
                        ZeroLengthModelItem = null;
4151 4564
                    }
4565
                    ReleaseCOMObjects(representation);
4566
                    representation = null;
4152 4567
                }
4568
                ReleaseCOMObjects(labelPersist);
4569
                labelPersist = null;
4153 4570
            }
4154
            else
4155
            {
4156
                LMItemNote _LMItemNote = null;
4157
                LMAAttribute _LMAAttribute = null;
4571
        }
4158 4572

  
4159
                double x = 0;
4160
                double y = 0;
4161
                double angle = text.ANGLE;
4162
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
4573
        /// <summary>
4574
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
4575
        /// </summary>
4576
        /// <param name="text"></param>
4577
        private void NormalTextModeling(Text text)
4578
        {
4579
            LMSymbol _LMSymbol = null;
4163 4580

  
4164
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4165
                text.SPPID.SPPID_X = x;
4166
                text.SPPID.SPPID_Y = y;
4581
            LMItemNote _LMItemNote = null;
4582
            LMAAttribute _LMAAttribute = null;
4167 4583

  
4168
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
4169
                if (_LMSymbol != null)
4584
            double x = 0;
4585
            double y = 0;
4586
            double angle = text.ANGLE;
4587
            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
4588

  
4589
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4590
            text.SPPID.SPPID_X = x;
4591
            text.SPPID.SPPID_Y = y;
4592

  
4593
            _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
4594
            if (_LMSymbol != null)
4595
            {
4596
                _LMSymbol.Commit();
4597
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4598
                if (_LMItemNote != null)
4170 4599
                {
4171
                    _LMSymbol.Commit();
4172
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4173
                    if (_LMItemNote != null)
4600
                    _LMItemNote.Commit();
4601
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4602
                    if (_LMAAttribute != null)
4174 4603
                    {
4604
                        _LMAAttribute.set_Value(text.VALUE);
4605
                        text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4175 4606
                        _LMItemNote.Commit();
4176
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4177
                        if (_LMAAttribute != null)
4178
                        {
4179
                            _LMAAttribute.set_Value(text.VALUE);
4180
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4181
                            _LMItemNote.Commit();
4182 4607

  
4183 4608

  
4184
                            double[] range = null;
4185
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4609
                        double[] range = null;
4610
                        foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4611
                        {
4612
                            double[] temp = null;
4613
                            GetSPPIDSymbolRange(labelPersist, ref temp);
4614
                            if (temp != null)
4186 4615
                            {
4187
                                double[] temp = null;
4188
                                GetSPPIDSymbolRange(labelPersist, ref temp);
4189
                                if (temp != null)
4616
                                if (range == null)
4617
                                    range = temp;
4618
                                else
4190 4619
                                {
4191
                                    if (range == null)
4192
                                        range = temp;
4193
                                    else
4194
                                    {
4195
                                        range = new double[] {
4620
                                    range = new double[] {
4196 4621
                                            Math.Min(range[0], temp[0]),
4197 4622
                                            Math.Min(range[1], temp[1]),
4198 4623
                                            Math.Max(range[2], temp[2]),
4199 4624
                                            Math.Max(range[3], temp[3])
4200 4625
                                        };
4201
                                    }
4202 4626
                                }
4203 4627
                            }
4204
                            if (range != null)
4205
                                correctList.Add(text);
4206
                            text.SPPID.Range = range;
4628
                        }
4629
                        text.SPPID.Range = range;
4630

  
4631
                        if (_LMAAttribute != null)
4632
                            ReleaseCOMObjects(_LMAAttribute);
4633
                        if (_LMItemNote != null)
4634
                            ReleaseCOMObjects(_LMItemNote);
4635
                    }
4207 4636

  
4637
                    TextCorrectModeling(text);
4638
                }
4639
            }
4640
            if (_LMSymbol != null)
4641
                ReleaseCOMObjects(_LMSymbol);
4642
        }
4208 4643

  
4209
                            if (_LMAAttribute != null)
4210
                                ReleaseCOMObjects(_LMAAttribute);
4211
                            if (_LMItemNote != null)
4212
                                ReleaseCOMObjects(_LMItemNote);
4644
        private void AssociationTextModeling(Text text)
4645
        {
4646
            LMSymbol _LMSymbol = null;
4647
            LMConnector connectedLMConnector = null;
4648
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
4649
            if (owner != null && owner.GetType() == typeof(Symbol))
4650
            {
4651
                Symbol symbol = owner as Symbol;
4652
                _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4653
                if (_LMSymbol != null)
4654
                {
4655
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4656
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4657
                    {
4658
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4659

  
4660
                        if (mapping != null)
4661
                        {
4662
                            double x = 0;
4663
                            double y = 0;
4664

  
4665
                            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4666
                            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4667
                            Array array = new double[] { 0, x, y };
4668
                            text.SPPID.SPPID_X = x;
4669
                            text.SPPID.SPPID_Y = y;
4670
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4671
                            if (_LMLabelPersist != null)
4672
                            {
4673
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4674
                                _LMLabelPersist.Commit();
4675
                                ReleaseCOMObjects(_LMLabelPersist);
4676
                            }
4677
                        }
4678
                    }
4679
                }
4680
            }
4681
            else if (owner != null && owner.GetType() == typeof(Line))
4682
            {
4683
                Line line = owner as Line;
4684
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
4685
                connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
4686

  
4687
                if (connectedLMConnector != null)
4688
                {
4689
                    BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4690
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4691
                    {
4692
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4693

  
4694
                        if (mapping != null)
4695
                        {
4696
                            double x = 0;
4697
                            double y = 0;
4698
                            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4699
                            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4700
                            Array array = new double[] { 0, x, y };
4701

  
4702
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4703
                            if (_LMLabelPersist != null)
4704
                            {
4705
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4706
                                _LMLabelPersist.Commit();
4707
                                ReleaseCOMObjects(_LMLabelPersist);
4708
                            }
4213 4709
                        }
4214 4710
                    }
4215 4711
                }
......
4218 4714
                ReleaseCOMObjects(_LMSymbol);
4219 4715
        }
4220 4716

  
4221
        private void TextCorrectModeling(Text text, List<Text> endList)
4717
        private void TextCorrectModeling(Text text)
4222 4718
        {
4719
            if (text.SPPID.Range == null)
4720
                return;
4721

  
4223 4722
            bool needRemodeling = false;
4224 4723
            bool loop = true;
4225 4724
            GridSetting gridSetting = GridSetting.GetInstance();
4226 4725
            while (loop)
4227 4726
            {
4228 4727
                loop = false;
4229
                foreach (var overlapText in endList)
4728
                foreach (var overlapText in document.TEXTINFOS)
4230 4729
                {
4730
                    if (overlapText.ASSOCIATION || overlapText == text || overlapText.SPPID.Range == null)
4731
                        continue;
4732

  
4231 4733
                    if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range))
4232 4734
                    {
4735
                        double percentX = 0;
4736
                        double percentY = 0;
4737
                        if (overlapText.X1 <= text.X2 && overlapText.X2 >= text.X1)
4738
                        {
4739
                            double gapX = Math.Min(overlapText.X2, text.X2) - Math.Max(overlapText.X1, text.X1);
4740
                            percentX = Math.Max(gapX / (overlapText.X2 - overlapText.X1), gapX / (text.X2 - text.X1));
4741
                        }
4742
                        if (overlapText.Y1 <= text.Y2 && overlapText.Y2 >= text.Y1)
4743
                        {
4744
                            double gapY = Math.Min(overlapText.Y2, text.Y2) - Math.Max(overlapText.Y1, text.Y1);
4745
                            percentY = Math.Max(gapY / (overlapText.Y2 - overlapText.Y1), gapY / (text.Y2 - text.Y1));
4746
                        }
4747

  
4233 4748
                        double tempX = 0;
4234 4749
                        double tempY = 0;
4235 4750
                        bool overlapX = false;
4236 4751
                        bool overlapY = false;
4237 4752
                        SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
4238
                        double angle = SPPIDUtil.CalcAngle(text.LOCATION_X, text.LOCATION_Y, overlapText.LOCATION_X, overlapText.LOCATION_Y);
4239
                        if (overlapY && angle >= 45)
4753
                        if (percentX >= percentY)
4240 4754
                        {
4241 4755
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
4242 4756
                            double move = gridSetting.Length * count;
......
4245 4759
                            needRemodeling = true;
4246 4760
                            loop = true;
4247 4761
                        }
4248
                        if (overlapX && angle <= 45)
4762
                        else
4249 4763
                        {
4250 4764
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
4251 4765
                            double move = gridSetting.Length * count;
......
4297 4811
                ReleaseCOMObjects(_LMSymbol);
4298 4812
                _LMSymbol = null;
4299 4813
            }
4814
        }
4815

  
4816
        private void AssociationTextCorrectModeling(Text text, List<Text> endTexts)
4817
        {
4818
            if (!string.IsNullOrEmpty(text.SPPID.RepresentationId))
4819
            {
4820
                List<Text> texts = new List<Text>();
4821
                LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
4822
                LMRepresentation representation = targetLabel.RepresentationObject;
4823
                Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id);
4824
                if (targetLabel.RepresentationObject != null && symbol != null)
4825
                {
4826
                    double[] symbolRange = null;
4827
                    GetSPPIDSymbolRange(symbol, ref symbolRange, true, true);
4828
                    if (symbolRange != null)
4829
                    {
4830
                        foreach (LMLabelPersist labelPersist in representation.LabelPersists)
4831
                        {
4832
                            Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION);
4833
                            if (findText != null)
4834
                            {
4835
                                double[] range = null;
4836
                                GetSPPIDSymbolRange(labelPersist, ref range);
4837
                                findText.SPPID.Range = range;
4838
                                texts.Add(findText);
4839
                            }
4840

  
4841
                            ReleaseCOMObjects(labelPersist);
4842
                        }
4843

  
4844
                        if (texts.Count > 0)
4845
                        {
4846
                            #region Sort Text By Y
4847
                            texts.Sort(SortTextByY);
4848
                            int SortTextByY(Text a, Text b)
4849
                            {
4850
                                return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]);
4851
                            }
4852
                            #endregion
4853

  
4854
                            #region 첫번째 Text로 기준 맞춤
4855
                            for (int i = 0; i < texts.Count; i++)
4856
                            {
4857
                                if (i != 0)
4858
                                {
4859
                                    Text currentText = texts[i];
4860
                                    Text prevText = texts[i - 1];
4861
                                    double minY = prevText.SPPID.Range[1];
4862
                                    double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2;
4863
                                    double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2;
4864
                                    double _gapX = centerX - centerPrevX;
4865
                                    double _gapY = currentText.SPPID.Range[3] - minY;
4866
                                    MoveText(currentText, _gapX, _gapY);
4867
                                }
4868
                            }
4869
                            List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList();
4870
                            List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList();
4871
                            List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList();
4872
                            List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList();
4873
                            rangeMinX.Sort();
4874
                            rangeMinY.Sort();
4875
                            rangeMaxX.Sort();
4876
                            rangeMaxY.Sort();
4877
                            double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2;
4878
                            double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2;
4879
                            #endregion
4880

  
4881
                            Text correctBySymbol = texts[0];
4882
                            double textCenterX = (text.X1 + text.X2) / 2;
4883
                            double textCenterY = (text.Y1 + text.Y2) / 2;
4884
                            double originX = 0;
4885
                            double originY = 0;
4886
                            SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY);
4887
                            double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY);
4888
                            double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2;
4889
                            double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2;
4890

  
4891
                            double gapX = 0;
4892
                            double gapY = 0;
4893
                            if (angle < 45)
4894
                            {
4895
                                // Text 오른쪽
4896
                                if (textCenterX > originX)
4897
                                {
4898
                                    gapX = rangeMinX[0] - symbolRange[2];
4899
                                    gapY = allTextCenterY - symbolCenterY;
4900
                                }
4901
                                // Text 왼쪽
4902
                                else
4903
                                {
4904
                                    gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0];
4905
                                    gapY = allTextCenterY - symbolCenterY;
4906
                                }
4907
                            }
4908
                            else
4909
                            {
4910
                                // Text 아래쪽
4911
                                if (textCenterY > originY)
4912
                                {
4913
                                    gapX = allTextCenterX - symbolCenterX;
4914
                                    gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1];
4915
                                }
4916
                                // Text 위쪽
4917
                                else
4918
                                {
4919
                                    gapX = allTextCenterX - symbolCenterX;
4920
                                    gapY = rangeMinY[0] - symbolRange[3];
4921
                                }
4922
                            }
4923

  
4924
                            foreach (var item in texts)
4925
                            {
4926
                                MoveText(item, gapX, gapY);
4927
                                RemodelingAssociationText(item);
4928
                            }
4929
                        }
4930
                    }
4931
                }
4932

  
4933
                void MoveText(Text moveText, double x, double y)
4934
                {
4935
                    moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x;
4936
                    moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y;
4937
                    moveText.SPPID.Range = new double[] {
4938
                        moveText.SPPID.Range[0] - x,
4939
                        moveText.SPPID.Range[1]- y,
4940
                        moveText.SPPID.Range[2]- x,
4941
                        moveText.SPPID.Range[3]- y
4942
                    };
4943
                }
4944

  
4945
                endTexts.AddRange(texts);
4946

  
4947
                ReleaseCOMObjects(targetLabel);
4948
                targetLabel = null;
4949
                ReleaseCOMObjects(representation);
4950
                representation = null;
4951
            }
4952
        }
4953

  
4954
        private void RemodelingAssociationText(Text text)
4955
        {
4956
            LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
4957
            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
4958
            removeLabel.Commit();
4959
            ReleaseCOMObjects(removeLabel);
4960
            removeLabel = null;
4961

  
4962
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
4963
            if (owner != null && owner.GetType() == typeof(Symbol))
4964
            {
4965
                Symbol symbol = owner as Symbol;
4966
                _LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4967
                if (_LMSymbol != null)
4968
                {
4969
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4970
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4971
                    {
4972
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4300 4973

  
4301
            endList.Add(text);
4974
                        if (mapping != null)
4975
                        {
4976
                            double x = 0;
4977
                            double y = 0;
4978

  
4979
                            Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y };
4980
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4981
                            if (_LMLabelPersist != null)
4982
                            {
4983
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4984
                                _LMLabelPersist.Commit();
4985
                            }
4986
                            ReleaseCOMObjects(_LMLabelPersist);
4987
                            _LMLabelPersist = null;
4988
                        }
4989
                    }
4990
                }
4991
                ReleaseCOMObjects(_LMSymbol);
4992
                _LMSymbol = null;
4993
            }
4302 4994
        }
4303 4995

  
4304 4996
        /// <summary>

내보내기 Unified diff

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