프로젝트

일반

사용자정보

개정판 6503fec8

ID6503fec80c7129c1dc70b86129ca7c994bff036c
상위 0a8db7fe
하위 7976c952

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

dev issue #1229 : text, note modeling

Change-Id: Ided03f2e3c8fac466df60d746cb4f4ea78d37662

차이점 보기:

DTI_PID/APIDConverter/AutoModeling.cs
100 100
            try
101 101
            {
102 102
                SplashScreenManager.ShowForm(typeof(APIDSplashScreen), true, true);
103
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 4);
103
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 5);
104 104
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetDocumentName, document.AvevaDrawingNumber + document.AvevaSheetNumber);
105 105
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetParent, Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle);
106 106

  
......
110 110
                RunOPCModeling();
111 111
                RunSymbolModeling();
112 112
                RunTextModeling();
113
                RunNoteModeling();
113 114
            }
114 115
            catch (System.Exception ex)
115 116
            {
......
163 164
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Text Modeling");
164 165
            foreach (var item in document.Texts)
165 166
            {
166

  
167
                TextModeling(item);
168
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
169
            }
170
        }
171
        private void RunNoteModeling()
172
        {
173
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Notes.Count);
174
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Note Modeling");
175
            foreach (var item in document.Texts)
176
            {
177
                TextModeling(item);
167 178
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
168 179
            }
169 180
        }
......
229 240
                }
230 241
            }
231 242
        }
243
        private void TextModeling(Text text)
244
        {
245
            if (text.TextAngle == TextAngle.None)
246
                return;
247

  
248
            if (text.Aveva.LabelType == LabelType.SingleText)
249
                DrawText(text.Aveva.X, text.Aveva.Y, text.Aveva.Height, text.VALUE);
250
            else if (text.Aveva.LabelType == LabelType.MultiText)
251
                DrawMultiLineText(text.Aveva.X, text.Aveva.Y, text.Aveva.Width, text.VALUE);
252

  
253
        }
254
        private void NoteModeling(Model.Note note)
255
        {
256
            if (note.TextAngle == TextAngle.None)
257
                return;
258

  
259
            if (note.Aveva.LabelType == LabelType.SingleNote)
260
                DrawText(note.Aveva.X, note.Aveva.Y, note.Aveva.Height, note.VALUE);
261
            else if (note.Aveva.LabelType == LabelType.MultiNote)
262
                DrawMultiLineText(note.Aveva.X, note.Aveva.Y, note.Aveva.Width, note.VALUE);
263

  
264
        }
232 265
        #endregion
233 266

  
234 267
        #region Drawing Method
......
397 430

  
398 431
            return handle;
399 432
        }
433
        private void DrawText(double x, double y, double height, string text)
434
        {
435
            // Get the current document and database
436
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
437
            Database acCurDb = acDoc.Database;
438

  
439
            // Start a transaction
440
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
441
            {
442
                // Open the Block table for read
443
                BlockTable acBlkTbl;
444
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
445
                                                OpenMode.ForRead) as BlockTable;
446

  
447
                // Open the Block table record Model space for write
448
                BlockTableRecord acBlkTblRec;
449
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
450
                                                OpenMode.ForWrite) as BlockTableRecord;
451

  
452
                // Create a single-line text object
453
                using (DBText acText = new DBText())
454
                {
455
                    acText.Position = new Point3d(x, y, 0);
456
                    acText.Height = height;
457
                    acText.TextString = text;
458

  
459
                    acBlkTblRec.AppendEntity(acText);
460
                    acTrans.AddNewlyCreatedDBObject(acText, true);
461
                }
462

  
463
                // Save the changes and dispose of the transaction
464
                acTrans.Commit();
465
            }
466
        }
467
        private void DrawMultiLineText(double x, double y, double width, string text)
468
        {
469
            // Get the current document and database
470
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
471
            Database acCurDb = acDoc.Database;
472

  
473
            // Start a transaction
474
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
475
            {
476
                // Open the Block table for read
477
                BlockTable acBlkTbl;
478
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
479
                                                OpenMode.ForRead) as BlockTable;
480

  
481
                // Open the Block table record Model space for write
482
                BlockTableRecord acBlkTblRec;
483
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
484
                                                OpenMode.ForWrite) as BlockTableRecord;
485

  
486
                // Create a multiline text object
487
                using (MText acMText = new MText())
488
                {
489
                    acMText.Location = new Point3d(x, y, 0);
490
                    acMText.Width = width;
491
                    acMText.Contents = text;
492

  
493
                    acBlkTblRec.AppendEntity(acMText);
494
                    acTrans.AddNewlyCreatedDBObject(acMText, true);
495
                }
496

  
497
                // Save the changes and dispose of the transaction
498
                acTrans.Commit();
499
            }
500
        }
400 501
        #endregion
401 502

  
402 503
        #region Autocad Utils
DTI_PID/APIDConverter/Model/PlantItem/Document.cs
740 740
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
741 741
            }
742 742

  
743
            foreach (var item in Texts)
744
            {
745
                item.Aveva = new AvevaLabelInfo();
746
                
747
                if (item.VALUE.Contains("\n"))
748
                {
749
                    double x = item.X1;
750
                    double y = SIZE_HEIGHT - item.Y1;
751
                    ConvertAvevaPoint(ref x, ref y);
752
                    item.Aveva.X = x;
753
                    item.Aveva.Y = y;
754

  
755
                    if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
756
                    {
757
                        double height = Math.Abs(item.Y1 - item.Y2);
758
                        ConvertAvevaPointY(ref height);
759
                        item.Aveva.Width = height;
760
                    }
761
                    else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
762
                    {
763
                        double height = Math.Abs(item.X1 - item.X2);
764
                        ConvertAvevaPointX(ref height);
765
                        item.Aveva.Width = height;
766
                    }
767

  
768
                    item.Aveva.LabelType = LabelType.MultiText;
769
                }
770
                else
771
                {
772
                    double x = item.X1;
773
                    double y = SIZE_HEIGHT - item.Y2;
774
                    ConvertAvevaPoint(ref x, ref y);
775
                    item.Aveva.X = x;
776
                    item.Aveva.Y = y;
777

  
778
                    if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
779
                    {
780
                        double height = Math.Abs(item.Y1 - item.Y2);
781
                        ConvertAvevaPointY(ref height);
782
                        item.Aveva.Height = height;
783
                    }
784
                    else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
785
                    {
786
                        double height = Math.Abs(item.X1 - item.X2);
787
                        ConvertAvevaPointX(ref height);
788
                        item.Aveva.Height = height;
789
                    }
790

  
791
                    item.Aveva.LabelType = LabelType.SingleText;
792
                }
793
                    
794

  
795
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
796
            }
797
            foreach (var item in Notes)
798
            {
799
                item.Aveva = new AvevaLabelInfo();
800

  
801
                if (item.VALUE.Contains(@"\n"))
802
                {
803
                    double x = item.X1;
804
                    double y = SIZE_HEIGHT - item.Y1;
805
                    ConvertAvevaPoint(ref x, ref y);
806
                    item.Aveva.X = x;
807
                    item.Aveva.Y = y;
808

  
809
                    if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
810
                    {
811
                        double height = Math.Abs(item.Y1 - item.Y2);
812
                        ConvertAvevaPointY(ref height);
813
                        item.Aveva.Width = height;
814
                    }
815
                    else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
816
                    {
817
                        double height = Math.Abs(item.X1 - item.X2);
818
                        ConvertAvevaPointX(ref height);
819
                        item.Aveva.Width = height;
820
                    }
821

  
822
                    item.Aveva.LabelType = LabelType.MultiNote;
823
                }
824
                else
825
                {
826
                    double x = item.X1;
827
                    double y = SIZE_HEIGHT - item.Y2;
828
                    ConvertAvevaPoint(ref x, ref y);
829
                    item.Aveva.X = x;
830
                    item.Aveva.Y = y;
831

  
832
                    if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
833
                    {
834
                        double height = Math.Abs(item.Y1 - item.Y2);
835
                        ConvertAvevaPointY(ref height);
836
                        item.Aveva.Height = height;
837
                    }
838
                    else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
839
                    {
840
                        double height = Math.Abs(item.X1 - item.X2);
841
                        ConvertAvevaPointX(ref height);
842
                        item.Aveva.Height = height;
843
                    }
844

  
845
                    item.Aveva.LabelType = LabelType.SingleNote;
846
                }
847

  
848
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
849
            }
850

  
743 851
            return result;
744 852
        }
745 853

  
......
753 861
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
754 862
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
755 863
        }
864
        public void ConvertAvevaPointX(ref double x)
865
        {
866
            decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX);
867
            decimal id2Width = Convert.ToDecimal(SIZE_WIDTH);
868

  
869
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
870
        }
871
        public void ConvertAvevaPointY(ref double y)
872
        {
873
            decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY);
874
            decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT);
875

  
876
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
877
        }
756 878

  
757 879
        private double RadianToDegree(double angle)
758 880
        {
DTI_PID/APIDConverter/Model/PlantItem/Note.cs
54 54
            {
55 55
                double gap = 0.05;
56 56
                if (value < gap)
57
                {
57 58
                    value = 0;
59
                    TextAngle = TextAngle.Degree0;
60
                }
58 61
                else if (1.57 - gap < value && value < 1.57 + gap)
62
                {
59 63
                    value = 90 * Math.PI / 180;
64
                    TextAngle = TextAngle.Degree90;
65
                }
60 66
                else if (3.14 - gap < value && value < 3.14 + gap)
67
                {
61 68
                    value = Math.PI;
69
                    TextAngle = TextAngle.Degree180;
70
                }
62 71
                else if (4.71 - gap < value && value < 4.71 + gap)
72
                {
63 73
                    value = 270 * Math.PI / 180;
74
                    TextAngle = TextAngle.Degree270;
75
                }
64 76

  
65 77
                _ANGLE = value;
66 78
            }
......
89 101
        public double Y1 { get; set; }
90 102
        public double Y2 { get; set; }
91 103
        public string OWNER { get => _OWNER; set => _OWNER = value; }
104
        public AvevaLabelInfo Aveva { get; set; }
105
        public TextAngle TextAngle { get; set; }
92 106
    }
93 107
}
DTI_PID/APIDConverter/Model/PlantItem/Other/AvevaLabelInfo.cs
9 9
    public enum LabelType
10 10
    {
11 11
        None,
12
        Text,
13
        LineNumber
12
        SingleText,
13
        MultiText,
14
        LineNumber,
15
        SingleNote,
16
        MultiNote
14 17
    }
15 18
    public class AvevaLabelInfo
16 19
    {
......
18 21
        public LabelType LabelType { get; set; }
19 22
        public double X { get; set; }
20 23
        public double Y { get; set; }
24
        public double Height { get; set; }
25
        public double Width { get; set; }
21 26
    }
22 27
}
DTI_PID/APIDConverter/Model/PlantItem/Text.cs
6 6

  
7 7
namespace AVEVA.PID.CustomizationUtility.Model
8 8
{
9
    public enum TextAngle
10
    {
11
        None,
12
        Degree0,
13
        Degree90,
14
        Degree180,
15
        Degree270
16
    }
9 17
    public class Text
10 18
    {
11 19
        private string _UID;
......
55 63
            {
56 64
                double gap = 0.05;
57 65
                if (value < gap)
66
                {
58 67
                    value = 0;
68
                    TextAngle = TextAngle.Degree0;
69
                }
59 70
                else if (1.57 - gap < value && value < 1.57 + gap)
71
                {
60 72
                    value = 90 * Math.PI / 180;
73
                    TextAngle = TextAngle.Degree90;
74
                }
61 75
                else if (3.14 - gap < value && value < 3.14 + gap)
76
                {
62 77
                    value = Math.PI;
78
                    TextAngle = TextAngle.Degree180;
79
                }
63 80
                else if (4.71 - gap < value && value < 4.71 + gap)
81
                {
64 82
                    value = 270 * Math.PI / 180;
83
                    TextAngle = TextAngle.Degree270;
84
                }
65 85

  
66 86
                _ANGLE = value;
67 87
            }
......
92 112
        public double X2 { get; set; }
93 113
        public double Y1 { get; set; }
94 114
        public double Y2 { get; set; }
115
        public AvevaLabelInfo Aveva { get; set; }
116
        public TextAngle TextAngle { get; set; }
95 117
    }
96 118
}

내보내기 Unified diff

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