프로젝트

일반

사용자정보

개정판 4e865771

ID4e8657719626886d77f19152f5637f2e79bd7890
상위 43628e91
하위 77717d18, f6761598

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

dev issue #507 : text label 위치 보정

Change-Id: I6fc4ffeb782ab97e703aa5b8224bb2d1e7dd9490

차이점 보기:

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, 21);
92 92
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
93 93

  
94 94
                    // Equipment Modeling
......
123 123
                    RunInputSpecBreakAttribute();
124 124
                    // Label Symbol Modeling
125 125
                    RunLabelSymbolModeling();
126
                    // Correct Text
127
                    RunCorrectAssociationText();
126 128

  
127 129
                    // Result Logging
128 130
                    document.CheckModelingResult();
......
898 900
                    Log.Write(ex.StackTrace);
899 901
                }
900 902
        }
901
        
903
        private void RunCorrectAssociationText()
904
        {
905
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
906
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Association Text");
907
            List<Text> endTexts = new List<Text>();
908
            foreach (var item in document.TEXTINFOS)
909
            {
910
                try
911
                {
912
                    if (item.ASSOCIATION && !endTexts.Contains(item))
913
                        AssociationTextCorrectModeling(item, endTexts);
914
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
915
                }
916
                catch (Exception ex)
917
                {
918
                    Log.Write("Error in NoteModeling");
919
                    Log.Write("UID : " + item.UID);
920
                    Log.Write(ex.Message);
921
                    Log.Write(ex.StackTrace);
922
                }
923
                
924
            }
925
        }
902 926
        /// <summary>
903 927
        /// 도면 생성 메서드
904 928
        /// </summary>
......
1400 1424
            ReleaseCOMObjects(_TargetItem);
1401 1425
        }
1402 1426

  
1403
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1427
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false)
1404 1428
        {
1405 1429
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1406 1430
            if (_TargetItem != null)
......
1410 1434
                double y1 = 0;
1411 1435
                double x2 = 0;
1412 1436
                double y2 = 0;
1413
                symbol2d.Range(out x1, out y1, out x2, out y2);
1414
                range = new double[] { x1, y1, x2, y2 };
1437
                if (!bForGraphic)
1438
                {
1439
                    symbol2d.Range(out x1, out y1, out x2, out y2);
1440
                    range = new double[] { x1, y1, x2, y2 };
1441
                }
1442
                else
1443
                {
1444
                    x1 = double.MaxValue;
1445
                    y1 = double.MaxValue;
1446
                    x2 = double.MinValue;
1447
                    y2 = double.MinValue;
1448
                    range = new double[] { x1, y1, x2, y2 };
1415 1449

  
1416
                foreach (var childSymbol in symbol.ChildSymbols)
1417
                    GetSPPIDChildSymbolRange(childSymbol, ref range);
1450
                    foreach (var item in symbol2d.DrawingObjects)
1451
                    {
1452
                        if (item.GetType() == typeof(Ingr.RAD2D.Line2d))
1453
                        {
1454
                            Ingr.RAD2D.Line2d rangeObject = item as Ingr.RAD2D.Line2d;
1455
                            if (rangeObject.Layer == "Default")
1456
                            {
1457
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1458
                                range = new double[] {
1459
                                Math.Min(x1, range[0]),
1460
                                Math.Min(y1, range[1]),
1461
                                Math.Max(x2, range[2]),
1462
                                Math.Max(y2, range[3])
1463
                            };
1464
                            }
1465
                        }
1466
                        else if (item.GetType() == typeof(Ingr.RAD2D.Circle2d))
1467
                        {
1468
                            Ingr.RAD2D.Circle2d rangeObject = item as Ingr.RAD2D.Circle2d;
1469
                            if (rangeObject.Layer == "Default")
1470
                            {
1471
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1472
                                range = new double[] {
1473
                                Math.Min(x1, range[0]),
1474
                                Math.Min(y1, range[1]),
1475
                                Math.Max(x2, range[2]),
1476
                                Math.Max(y2, range[3])
1477
                            };
1478
                            }
1479
                        }
1480
                        else if (item.GetType() == typeof(Ingr.RAD2D.Rectangle2d))
1481
                        {
1482
                            Ingr.RAD2D.Rectangle2d rangeObject = item as Ingr.RAD2D.Rectangle2d;
1483
                            if (rangeObject.Layer == "Default")
1484
                            {
1485
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1486
                                range = new double[] {
1487
                                Math.Min(x1, range[0]),
1488
                                Math.Min(y1, range[1]),
1489
                                Math.Max(x2, range[2]),
1490
                                Math.Max(y2, range[3])
1491
                            };
1492
                            }
1493
                        }
1494
                        else if (item.GetType() == typeof(Ingr.RAD2D.Arc2d))
1495
                        {
1496
                            Ingr.RAD2D.Arc2d rangeObject = item as Ingr.RAD2D.Arc2d;
1497
                            if (rangeObject.Layer == "Default")
1498
                            {
1499
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1500
                                range = new double[] {
1501
                                Math.Min(x1, range[0]),
1502
                                Math.Min(y1, range[1]),
1503
                                Math.Max(x2, range[2]),
1504
                                Math.Max(y2, range[3])
1505
                            };
1506
                            }
1507
                        }
1508
                        else
1509
                            Log.Write(item.GetType().ToString());
1510
                    }
1511
                }
1418 1512

  
1513
                if (!bOnlySymbol)
1514
                {
1515
                    foreach (var childSymbol in symbol.ChildSymbols)
1516
                        GetSPPIDChildSymbolRange(childSymbol, ref range);
1517
                }
1419 1518
                ReleaseCOMObjects(_TargetItem);
1420 1519
            }
1421 1520
        }
......
1424 1523
        {
1425 1524
            if (labelPersist != null)
1426 1525
            {
1526
                double x1 = double.MaxValue;
1527
                double y1 = double.MaxValue;
1528
                double x2 = double.MinValue;
1529
                double y2 = double.MinValue;
1530
                range = new double[] { x1, y1, x2, y2 };
1531

  
1427 1532
                Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject;
1428
                if (dependency != null)
1533
                foreach (var item in dependency.DrawingObjects)
1429 1534
                {
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 };
1535
                    Ingr.RAD2D.TextBox textBox = item as Ingr.RAD2D.TextBox;
1536
                    if (textBox != null)
1537
                    {
1538
                        if (dependency != null)
1539
                        {
1540
                            double tempX1;
1541
                            double tempY1;
1542
                            double tempX2;
1543
                            double tempY2;
1544
                            textBox.Range(out tempX1, out tempY1, out tempX2, out tempY2);
1545
                            x1 = Math.Min(x1, tempX1);
1546
                            y1 = Math.Min(y1, tempY1);
1547
                            x2 = Math.Max(x2, tempX2);
1548
                            y2 = Math.Max(y2, tempY2);
1549

  
1550
                            range = new double[] { x1, y1, x2, y2 };
1551
                        }
1552
                    }
1436 1553
                }
1554
                
1437 1555
            }
1438 1556
        }
1439 1557

  
......
2867 2985
                    if (slopeType == SlopeType.HORIZONTAL)
2868 2986
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2869 2987
                    else if (slopeType == SlopeType.VERTICAL)
2870
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
2988
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2871 2989
                }
2872 2990
                else if (targetLine != null)
2873 2991
                {
2874 2992
                    if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2875 2993
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2876 2994
                    else if (targetLine.SlopeType == SlopeType.VERTICAL)
2877
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
2995
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2878 2996
                }
2879 2997
                else if (connLine != null)
2880 2998
                {
2881 2999
                    if (connLine.SlopeType == SlopeType.HORIZONTAL)
2882 3000
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2883 3001
                    else if (connLine.SlopeType == SlopeType.VERTICAL)
2884
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
3002
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
2885 3003
                }
2886 3004
            }
2887 3005
            else
......
3843 3961
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3844 3962
                        if (_Attribute != null)
3845 3963
                        {
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
                            }
3964
                            //object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
3965
                            //if (associItem != null)
3966
                            //{
3967
                            //    if (associItem.GetType() == typeof(Text))
3968
                            //    {
3969
                            //        Text text = associItem as Text;
3970
                            //        text.SPPID.RepresentationId = "Attribute";
3971
                            //    }
3972
                            //    else if (associItem.GetType() == typeof(Note))
3973
                            //    {
3974
                            //        Note note = associItem as Note;
3975
                            //        note.SPPID.RepresentationId = "Attribute";
3976
                            //    }
3977
                            //}
3860 3978
                            _Attribute.set_Value(item.VALUE);
3861 3979
                            // OPC 일경우 Attribute 저장
3862 3980
                            if (targetItem.GetType() == typeof(Symbol))
......
4107 4225
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4108 4226
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4109 4227
                                Array array = new double[] { 0, x, y };
4228
                                text.SPPID.SPPID_X = x;
4229
                                text.SPPID.SPPID_Y = y;
4110 4230
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4111 4231
                                if (_LMLabelPersist != null)
4112 4232
                                {
......
4301 4421
            endList.Add(text);
4302 4422
        }
4303 4423

  
4424
        private void AssociationTextCorrectModeling(Text text, List<Text> endTexts)
4425
        {
4426
            if (!string.IsNullOrEmpty(text.SPPID.RepresentationId))
4427
            {
4428
                List<Text> texts = new List<Text>();
4429
                LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
4430
                LMRepresentation representation = targetLabel.RepresentationObject;
4431
                Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id);
4432
                if (targetLabel.RepresentationObject != null && symbol != null)
4433
                {
4434
                    double[] symbolRange = null;
4435
                    GetSPPIDSymbolRange(symbol, ref symbolRange, true, true);
4436
                    if (symbolRange != null)
4437
                    {
4438
                        foreach (LMLabelPersist labelPersist in representation.LabelPersists)
4439
                        {
4440
                            Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION);
4441
                            if (findText != null)
4442
                            {
4443
                                double[] range = null;
4444
                                GetSPPIDSymbolRange(labelPersist, ref range);
4445
                                findText.SPPID.Range = range;
4446
                                texts.Add(findText);
4447
                            }
4448

  
4449
                            ReleaseCOMObjects(labelPersist);
4450
                        }
4451

  
4452
                        if (texts.Count > 0)
4453
                        {
4454
                            #region Sort Text By Y
4455
                            texts.Sort(SortTextByY);
4456
                            int SortTextByY(Text a, Text b)
4457
                            {
4458
                                return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]);
4459
                            }
4460
                            #endregion
4461

  
4462
                            #region 첫번째 Text로 기준 맞춤
4463
                            for (int i = 0; i < texts.Count; i++)
4464
                            {
4465
                                if (i != 0)
4466
                                {
4467
                                    Text currentText = texts[i];
4468
                                    Text prevText = texts[i - 1];
4469
                                    double minY = prevText.SPPID.Range[1];
4470
                                    double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2;
4471
                                    double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2;
4472
                                    double _gapX = centerX - centerPrevX;
4473
                                    double _gapY = currentText.SPPID.Range[3] - minY;
4474
                                    MoveText(currentText, _gapX, _gapY);
4475
                                }
4476
                            }
4477
                            List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList();
4478
                            List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList();
4479
                            List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList();
4480
                            List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList();
4481
                            rangeMinX.Sort();
4482
                            rangeMinY.Sort();
4483
                            rangeMaxX.Sort();
4484
                            rangeMaxY.Sort();
4485
                            double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2;
4486
                            double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2;
4487
                            #endregion
4488

  
4489
                            Text correctBySymbol = texts[0];
4490
                            double textCenterX = (text.X1 + text.X2) / 2;
4491
                            double textCenterY = (text.Y1 + text.Y2) / 2;
4492
                            double originX = 0;
4493
                            double originY = 0;
4494
                            SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY);
4495
                            double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY);
4496
                            double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2;
4497
                            double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2;
4498

  
4499
                            double gapX = 0;
4500
                            double gapY = 0;
4501
                            if (angle < 45)
4502
                            {
4503
                                // Text 오른쪽
4504
                                if (textCenterX > originX)
4505
                                {
4506
                                    gapX = rangeMinX[0] - symbolRange[2];
4507
                                    gapY = allTextCenterY - symbolCenterY;
4508
                                }
4509
                                // Text 왼쪽
4510
                                else
4511
                                {
4512
                                    gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0];
4513
                                    gapY = allTextCenterY - symbolCenterY;
4514
                                }
4515
                            }
4516
                            else
4517
                            {
4518
                                // Text 아래쪽
4519
                                if (textCenterY > originY)
4520
                                {
4521
                                    gapX = allTextCenterX - symbolCenterX;
4522
                                    gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1];
4523
                                }
4524
                                // Text 위쪽
4525
                                else
4526
                                {
4527
                                    gapX = allTextCenterX - symbolCenterX;
4528
                                    gapY = rangeMinY[0] - symbolRange[3];
4529
                                }
4530
                            }
4531

  
4532
                            foreach (var item in texts)
4533
                            {
4534
                                MoveText(item, gapX, gapY);
4535
                                RemodelingAssociationText(item);
4536
                            }
4537
                        }
4538
                    }
4539
                }
4540

  
4541
                void MoveText(Text moveText, double x, double y)
4542
                {
4543
                    moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x;
4544
                    moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y;
4545
                    moveText.SPPID.Range = new double[] {
4546
                        moveText.SPPID.Range[0] - x,
4547
                        moveText.SPPID.Range[1]- y,
4548
                        moveText.SPPID.Range[2]- x,
4549
                        moveText.SPPID.Range[3]- y
4550
                    };
4551
                }
4552

  
4553
                endTexts.AddRange(texts);
4554

  
4555
                ReleaseCOMObjects(targetLabel);
4556
                targetLabel = null;
4557
                ReleaseCOMObjects(representation);
4558
                representation = null;
4559
            }
4560
        }
4561

  
4562
        private void RemodelingAssociationText(Text text)
4563
        {
4564
            LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
4565
            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
4566
            removeLabel.Commit();
4567
            ReleaseCOMObjects(removeLabel);
4568
            removeLabel = null;
4569

  
4570
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
4571
            if (owner != null && owner.GetType() == typeof(Symbol))
4572
            {
4573
                Symbol symbol = owner as Symbol;
4574
                _LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4575
                if (_LMSymbol != null)
4576
                {
4577
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4578
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4579
                    {
4580
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4581

  
4582
                        if (mapping != null)
4583
                        {
4584
                            double x = 0;
4585
                            double y = 0;
4586

  
4587
                            Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y };
4588
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4589
                            if (_LMLabelPersist != null)
4590
                            {
4591
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4592
                                _LMLabelPersist.Commit();
4593
                            }
4594
                            ReleaseCOMObjects(_LMLabelPersist);
4595
                            _LMLabelPersist = null;
4596
                        }
4597
                    }
4598
                }
4599
                ReleaseCOMObjects(_LMSymbol);
4600
                _LMSymbol = null;
4601
            }
4602
        }
4603

  
4304 4604
        /// <summary>
4305 4605
        /// Note Modeling
4306 4606
        /// </summary>

내보내기 Unified diff

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