프로젝트

일반

사용자정보

개정판 1299077b

ID1299077bebee27be6e25a9bc7573593bafd4ec8b
상위 6efd5250
하위 889eb58d

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

dev issue #1191 : Text, Note 좌표 보정

Change-Id: I5602e50fc2afdbeb337bceb4eb2e08705b922d6e

차이점 보기:

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

  
94 94
                    // Equipment Modeling
......
643 643
        {
644 644
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
645 645
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
646
            List<Note> correctList = new List<Note>();
646 647
            foreach (var item in document.NOTES)
647 648
                try
648 649
                {
649
                    NoteModeling(item);
650
                    NoteModeling(item, correctList);
651
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
652
                }
653
                catch (Exception ex)
654
                {
655
                    Log.Write("Error in NoteModeling");
656
                    Log.Write("UID : " + item.UID);
657
                    Log.Write(ex.Message);
658
                    Log.Write(ex.StackTrace);
659
                }
660

  
661
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
662
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Note");
663
            SortNote(correctList);
664
            List<Note> endList = new List<Note>();
665
            if (correctList.Count > 0)
666
                endList.Add(correctList[0]);
667
            foreach (var item in document.NOTES)
668
                try
669
                {
670
                    if (!endList.Contains(item))
671
                        NoteCorrectModeling(item, endList);
650 672
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
651 673
                }
652 674
                catch (Exception ex)
......
661 683
        {
662 684
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
663 685
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
686
            List<Text> correctList = new List<Text>();
664 687
            foreach (var item in document.TEXTINFOS)
665 688
                try
666 689
                {
667
                    TextModeling(item);
690
                    TextModeling(item, correctList);
691
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
692
                }
693
                catch (Exception ex)
694
                {
695
                    Log.Write("Error in TextModeling");
696
                    Log.Write("UID : " + item.UID);
697
                    Log.Write(ex.Message);
698
                    Log.Write(ex.StackTrace);
699
                }
700

  
701
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
702
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Text");
703
            SortText(correctList);
704
            List<Text> endList = new List<Text>();
705
            if (correctList.Count > 0)
706
                endList.Add(correctList[0]);
707
            foreach (var item in correctList)
708
                try
709
                {
710
                    if (!endList.Contains(item))
711
                        TextCorrectModeling(item, endList);
668 712
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
669 713
                }
670 714
                catch (Exception ex)
......
1156 1200
            }
1157 1201
        }
1158 1202

  
1203
        private void GetSPPIDSymbolRange(LMLabelPersist labelPersist, ref double[] range)
1204
        {
1205
            if (labelPersist != null)
1206
            {
1207
                Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject;
1208
                if (dependency != null)
1209
                {
1210
                    double x1 = 0;
1211
                    double y1 = 0;
1212
                    double x2 = 0;
1213
                    double y2 = 0;
1214
                    dependency.Range(out x1, out y1, out x2, out y2);
1215
                    range = new double[] { x1, y1, x2, y2 };
1216
                }
1217
            }
1218
        }
1219

  
1159 1220
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1160 1221
        {
1161 1222
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
......
3684 3745
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3685 3746
        /// </summary>
3686 3747
        /// <param name="text"></param>
3687
        private void TextModeling(Text text)
3748
        private void TextModeling(Text text, List<Text> correctList)
3688 3749
        {
3689 3750
            LMSymbol _LMSymbol = null;
3690 3751
            LMConnector connectedLMConnector = null;
......
3709 3770
                                double y = 0;
3710 3771

  
3711 3772
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3773
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
3712 3774
                                Array array = new double[] { 0, x, y };
3713

  
3714 3775
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3715 3776
                                if (_LMLabelPersist != null)
3716 3777
                                {
......
3739 3800
                            {
3740 3801
                                double x = 0;
3741 3802
                                double y = 0;
3742

  
3743 3803
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3804
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
3744 3805
                                Array array = new double[] { 0, x, y };
3745 3806

  
3746 3807
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
......
3765 3826
                double angle = text.ANGLE;
3766 3827
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3767 3828

  
3829
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
3830
                text.SPPID.SPPID_X = x;
3831
                text.SPPID.SPPID_Y = y;
3832

  
3768 3833
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3769 3834
                if (_LMSymbol != null)
3770 3835
                {
......
3780 3845
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
3781 3846
                            _LMItemNote.Commit();
3782 3847

  
3848

  
3849
                            double[] range = null;
3850
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
3851
                            {
3852
                                double[] temp = null;
3853
                                GetSPPIDSymbolRange(labelPersist, ref temp);
3854
                                if (temp != null)
3855
                                {
3856
                                    if (range == null)
3857
                                        range = temp;
3858
                                    else
3859
                                    {
3860
                                        range = new double[] {
3861
                                            Math.Min(range[0], temp[0]),
3862
                                            Math.Min(range[1], temp[1]),
3863
                                            Math.Max(range[2], temp[2]),
3864
                                            Math.Max(range[3], temp[3])
3865
                                        };
3866
                                    }
3867
                                }
3868
                            }
3869
                            if (range != null)
3870
                                correctList.Add(text);
3871
                            text.SPPID.Range = range;
3872

  
3873

  
3783 3874
                            if (_LMAAttribute != null)
3784 3875
                                ReleaseCOMObjects(_LMAAttribute);
3785 3876
                            if (_LMItemNote != null)
......
3792 3883
                ReleaseCOMObjects(_LMSymbol);
3793 3884
        }
3794 3885

  
3886
        private void TextCorrectModeling(Text text, List<Text> endList)
3887
        {
3888
            bool needRemodeling = false;
3889
            bool loop = true;
3890
            GridSetting gridSetting = GridSetting.GetInstance();
3891
            while (loop)
3892
            {
3893
                loop = false;
3894
                foreach (var overlapText in endList)
3895
                {
3896
                    if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range))
3897
                    {
3898
                        double tempX = 0;
3899
                        double tempY = 0;
3900
                        bool overlapX = false;
3901
                        bool overlapY = false;
3902
                        SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
3903
                        double angle = SPPIDUtil.CalcAngle(text.LOCATION_X, text.LOCATION_Y, overlapText.LOCATION_X, overlapText.LOCATION_Y);
3904
                        if (overlapY && angle >= 45)
3905
                        {
3906
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
3907
                            double move = gridSetting.Length * count;
3908
                            text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move;
3909
                            text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move };
3910
                            needRemodeling = true;
3911
                            loop = true;
3912
                        }
3913
                        if (overlapX && angle <= 45)
3914
                        {
3915
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
3916
                            double move = gridSetting.Length * count;
3917
                            text.SPPID.SPPID_X = text.SPPID.SPPID_X + move;
3918
                            text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] };
3919
                            needRemodeling = true;
3920
                            loop = true;
3921
                        }
3922
                    }
3923
                }
3924
            }
3925
            
3926

  
3927
            if (needRemodeling)
3928
            {
3929
                LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId);
3930
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
3931
                text.SPPID.RepresentationId = null;
3932

  
3933
                LMItemNote _LMItemNote = null;
3934
                LMAAttribute _LMAAttribute = null;
3935
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE);
3936
                if (_LMSymbol != null)
3937
                {
3938
                    _LMSymbol.Commit();
3939
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3940
                    if (_LMItemNote != null)
3941
                    {
3942
                        _LMItemNote.Commit();
3943
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3944
                        if (_LMAAttribute != null)
3945
                        {
3946
                            _LMAAttribute.set_Value(text.VALUE);
3947
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
3948
                            _LMItemNote.Commit();
3949

  
3950
                            ReleaseCOMObjects(_LMAAttribute);
3951
                            ReleaseCOMObjects(_LMItemNote);
3952
                        }
3953
                    }
3954
                }
3955

  
3956
                ReleaseCOMObjects(symbol);
3957
                symbol = null;
3958
                ReleaseCOMObjects(_LMItemNote);
3959
                _LMItemNote = null;
3960
                ReleaseCOMObjects(_LMAAttribute);
3961
                _LMAAttribute = null;
3962
                ReleaseCOMObjects(_LMSymbol);
3963
                _LMSymbol = null;
3964
            }
3965

  
3966
            endList.Add(text);
3967
        }
3968

  
3795 3969
        /// <summary>
3796 3970
        /// Note Modeling
3797 3971
        /// </summary>
3798 3972
        /// <param name="note"></param>
3799
        private void NoteModeling(Note note)
3973
        private void NoteModeling(Note note, List<Note> correctList)
3800 3974
        {
3801 3975
            LMSymbol _LMSymbol = null;
3802 3976
            LMItemNote _LMItemNote = null;
......
3808 3982
                double y = 0;
3809 3983

  
3810 3984
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
3985
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
3986
                note.SPPID.SPPID_X = x;
3987
                note.SPPID.SPPID_Y = y;
3811 3988

  
3812 3989
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3813 3990
                if (_LMSymbol != null)
......
3822 3999
                        {
3823 4000
                            _LMAAttribute.set_Value(note.VALUE);
3824 4001
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4002

  
4003
                            double[] range = null;
4004
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4005
                            {
4006
                                double[] temp = null;
4007
                                GetSPPIDSymbolRange(labelPersist, ref temp);
4008
                                if (temp != null)
4009
                                {
4010
                                    if (range == null)
4011
                                        range = temp;
4012
                                    else
4013
                                    {
4014
                                        range = new double[] {
4015
                                            Math.Min(range[0], temp[0]),
4016
                                            Math.Min(range[1], temp[1]),
4017
                                            Math.Max(range[2], temp[2]),
4018
                                            Math.Max(range[3], temp[3])
4019
                                        };
4020
                                    }
4021
                                }
4022
                            }
4023
                            if (range != null)
4024
                                correctList.Add(note);
4025
                            note.SPPID.Range = range;
4026

  
4027

  
3825 4028
                            _LMItemNote.Commit();
3826 4029
                        }
3827 4030
                    }
......
3836 4039
                ReleaseCOMObjects(_LMSymbol);
3837 4040
        }
3838 4041

  
4042
        private void NoteCorrectModeling(Note note, List<Note> endList)
4043
        {
4044
            bool needRemodeling = false;
4045
            bool loop = true;
4046
            GridSetting gridSetting = GridSetting.GetInstance();
4047
            while (loop)
4048
            {
4049
                loop = false;
4050
                foreach (var overlap in endList)
4051
                {
4052
                    if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range))
4053
                    {
4054
                        double tempX = 0;
4055
                        double tempY = 0;
4056
                        bool overlapX = false;
4057
                        bool overlapY = false;
4058
                        SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
4059
                        double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y);
4060
                        if (overlapY && angle >= 45)
4061
                        {
4062
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
4063
                            double move = gridSetting.Length * count;
4064
                            note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move;
4065
                            note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move };
4066
                            needRemodeling = true;
4067
                            loop = true;
4068
                        }
4069
                        if (overlapX && angle <= 45)
4070
                        {
4071
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
4072
                            double move = gridSetting.Length * count;
4073
                            note.SPPID.SPPID_X = note.SPPID.SPPID_X + move;
4074
                            note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] };
4075
                            needRemodeling = true;
4076
                            loop = true;
4077
                        }
4078
                    }
4079
                }
4080
            }
4081

  
4082

  
4083
            if (needRemodeling)
4084
            {
4085
                LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId);
4086
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
4087
                note.SPPID.RepresentationId = null;
4088

  
4089
                LMItemNote _LMItemNote = null;
4090
                LMAAttribute _LMAAttribute = null;
4091
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE);
4092
                if (_LMSymbol != null)
4093
                {
4094
                    _LMSymbol.Commit();
4095
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4096
                    if (_LMItemNote != null)
4097
                    {
4098
                        _LMItemNote.Commit();
4099
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4100
                        if (_LMAAttribute != null)
4101
                        {
4102
                            _LMAAttribute.set_Value(note.VALUE);
4103
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4104
                            _LMItemNote.Commit();
4105

  
4106
                            ReleaseCOMObjects(_LMAAttribute);
4107
                            ReleaseCOMObjects(_LMItemNote);
4108
                        }
4109
                    }
4110
                }
4111

  
4112
                ReleaseCOMObjects(symbol);
4113
                symbol = null;
4114
                ReleaseCOMObjects(_LMItemNote);
4115
                _LMItemNote = null;
4116
                ReleaseCOMObjects(_LMAAttribute);
4117
                _LMAAttribute = null;
4118
                ReleaseCOMObjects(_LMSymbol);
4119
                _LMSymbol = null;
4120
            }
4121

  
4122
            endList.Add(note);
4123
        }
4124

  
3839 4125
        private void JoinRunBySameType(string modelItemId, ref string survivorId)
3840 4126
        {
3841 4127
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
......
4088 4374
            }
4089 4375
        }
4090 4376

  
4377
        private void SortText(List<Text> texts)
4378
        {
4379
            texts.Sort(Sort);
4380

  
4381
            int Sort(Text a, Text b)
4382
            {
4383
                int yRetval = CompareY(a, b);
4384
                if (yRetval != 0)
4385
                {
4386
                    return yRetval;
4387
                }
4388
                else
4389
                {
4390
                    return CompareX(a, b);
4391
                }
4392
            }
4393

  
4394
            int CompareY(Text a, Text b)
4395
            {
4396
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
4397
            }
4398

  
4399
            int CompareX(Text a, Text b)
4400
            {
4401
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
4402
            }
4403
        }
4404
        private void SortNote(List<Note> notes)
4405
        {
4406
            notes.Sort(Sort);
4407

  
4408
            int Sort(Note a, Note b)
4409
            {
4410
                int yRetval = CompareY(a, b);
4411
                if (yRetval != 0)
4412
                {
4413
                    return yRetval;
4414
                }
4415
                else
4416
                {
4417
                    return CompareX(a, b);
4418
                }
4419
            }
4420

  
4421
            int CompareY(Note a, Note b)
4422
            {
4423
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
4424
            }
4425

  
4426
            int CompareX(Note a, Note b)
4427
            {
4428
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
4429
            }
4430
        }
4431

  
4091 4432
        private void SortBranchLines()
4092 4433
        {
4093 4434
            BranchLines.Sort(SortBranchLine);

내보내기 Unified diff

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