프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / Utils / APIDUtils.cs @ 34937d2c

이력 | 보기 | 이력해설 | 다운로드 (5.63 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.IO;
7
using System.Reflection;
8
using System.Data;
9
using Autodesk.AutoCAD.EditorInput;
10

    
11
using AVEVA.PID.Components;
12
using AVEVA.PID.GUI;
13
using AVEVA.PID.Common;
14
using AVEVA.PID.DWGSelector;
15

    
16
using AVEVA.PID.CustomizationUtility.DB;
17
using AVEVA.PID.CustomizationUtility.Model;
18
using AVEVA.PID.CustomizationUtility.Properties;
19

    
20
namespace AVEVA.PID.CustomizationUtility
21
{
22
    public class APIDUtils
23
    {
24
        #region APID Converter
25
        public static object FindObjectByUID(Document document, string UID)
26
        {
27
            if (!string.IsNullOrEmpty(UID) && UID != "None")
28
            {
29
                foreach (PlantItem item in document.PlantItems)
30
                {
31
                    if (item.UID == UID)
32
                        return item;
33
                }
34
            }
35

    
36
            return null;
37
        }
38
        public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY)
39
        {
40
            try
41
            {
42
                string[] pointArr = sPoint.Split(new char[] { ',' });
43
                if (pointArr.Length == 2)
44
                {
45
                    dX = Convert.ToDouble(pointArr[0]);
46
                    dY = Convert.ToDouble(pointArr[1]);
47
                }
48
            }
49
            catch (Exception)
50
            {
51
                dX = 0;
52
                dY = 0;
53
                return false;
54
            }
55

    
56
            return true;
57
        }
58
        public static bool IsConnectedLine(Line line1, Line line2)
59
        {
60
            bool result = false;
61

    
62
            if (line1.CONNECTORS.Find(x => x.ConnectedObject == line2) != null &&
63
                line2.CONNECTORS.Find(x => x.ConnectedObject == line1) != null)
64
                result = true;
65

    
66
            return result;
67
        }
68
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2)
69
        {
70
            if (x1 - x2 == 0)
71
                return SlopeType.VERTICAL;
72
            else
73
            {
74
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
75
                if (angle <= 15)
76
                    return SlopeType.HORIZONTAL;
77
                else if (angle >= 75)
78
                    return SlopeType.VERTICAL;
79
                else
80
                    return SlopeType.Slope;
81
            }
82
        }
83
        #endregion
84

    
85
        #region Only AVEVA
86
        public static void SetAvevaExplorer()
87
        {
88
            bool exist = false;
89
            string sName = "APID Converter";
90
            for (int i = 0; i < Aveva.Command.AvevaCommands.projectExplorer.Count; i++)
91
            {
92
                if (Aveva.Command.AvevaCommands.projectExplorer[i].Name == sName)
93
                {
94
                    exist = true;
95
                    Aveva.Command.AvevaCommands.projectExplorer.Remove(i);
96
                    break;
97
                }
98
            }
99

    
100
            if (!exist)
101
            {
102
                Aveva.Command.AvevaCommands.projectExplorer.Add(sName, new APIDConverterExplorer());
103
                Aveva.Command.AvevaCommands.projectExplorer.Activate(Aveva.Command.AvevaCommands.projectExplorer.Count - 1);
104
            }
105
        }
106
        public static List<string> GetPipeStyle()
107
        {
108
            List<string> list = new List<string>();
109
            Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL");
110
            object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE");
111
            if (objPipeStyle != null)
112
            {
113
                Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo;
114
                foreach (var item in pipeStyleCombo.Items)
115
                {
116
                    Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton;
117
                    list.Add(loop.AutomationName);
118
                }
119
            }
120

    
121
            return list;
122
        }
123
        public static List<string> GetSignalStyle()
124
        {
125
            List<string> list = new List<string>();
126
            Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_SIGNAL_PANEL");
127
            object objPipeStyle = GUIUtils.FindItem(items, "SIGNALSTYLE");
128
            if (objPipeStyle != null)
129
            {
130
                Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo;
131
                foreach (var item in pipeStyleCombo.Items)
132
                {
133
                    Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton;
134
                    list.Add(loop.AutomationName);
135
                }
136
            }
137

    
138
            return list;
139
        }
140
        public static Dictionary<PID.Utilities.PipeLabelName, PID.Utilities.PipeLabelHelper.PipeDisplayLabelField> GetPipeAttribute()
141
        {
142
            return PID.Utilities.PipeLabelHelper.GetPipeDisplayLabelFields().ToDictionary(x => x.Key, y => y.Value);
143
        }
144
        public static DataTable GetSymbolAttributes()
145
        {
146
            DataTable dt = new DataTable();
147
            dt.Columns.Add("Name");
148
            dt.Columns.Add("DisplayType");
149
            dt.Columns.Add("Value");
150
            dt.Columns.Add("DisplayMember");
151

    
152
            #region UDA
153
            DataTable udaDT = Project_DB.SelectUDADetails();
154
            udaDT = udaDT.DefaultView.ToTable(true, "UDAName");
155
            string udaDisplay = "User Defined Attribute";
156
            foreach (DataRow item in udaDT.Rows)
157
                dt.Rows.Add(item["UDAName"], udaDisplay, item["UDAName"] + "|UDA", item["UDAName"] + " | " + udaDisplay);
158
            #endregion
159

    
160
            return dt;
161
        }
162

    
163

    
164
        #endregion
165
    }
166
}
클립보드 이미지 추가 (최대 크기: 500 MB)