hytos / DTI_PID / APIDConverter / Utils / APIDUtils.cs @ 4622d687
이력 | 보기 | 이력해설 | 다운로드 (7.14 KB)
1 | 4e320fcb | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | 59184d1b | gaqhf | using System.IO; |
7 | using System.Reflection; |
||
8 | 77a33d5f | gaqhf | using System.Data; |
9 | 14540282 | gaqhf | using Autodesk.AutoCAD.EditorInput; |
10 | 59184d1b | gaqhf | |
11 | using AVEVA.PID.Components; |
||
12 | using AVEVA.PID.GUI; |
||
13 | using AVEVA.PID.Common; |
||
14 | using AVEVA.PID.DWGSelector; |
||
15 | 4e320fcb | gaqhf | |
16 | 5aec7e24 | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
17 | using AVEVA.PID.CustomizationUtility.Model; |
||
18 | using AVEVA.PID.CustomizationUtility.Properties; |
||
19 | |||
20 | 4e320fcb | gaqhf | namespace AVEVA.PID.CustomizationUtility |
21 | { |
||
22 | public class APIDUtils |
||
23 | { |
||
24 | 32954c7f | gaqhf | #region APID Converter |
25 | 5aec7e24 | gaqhf | 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 | 4e320fcb | gaqhf | |
36 | 5aec7e24 | gaqhf | return null; |
37 | } |
||
38 | 32954c7f | gaqhf | 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 | 53344e2c | gaqhf | 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 | 016701e5 | gaqhf | 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 | 32954c7f | gaqhf | #endregion |
84 | 88cb9898 | gaqhf | |
85 | 32954c7f | gaqhf | #region Only AVEVA |
86 | 88cb9898 | gaqhf | 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 | 9ee9b61d | gaqhf | } |
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 | 88cb9898 | gaqhf | } |
140 | 77a33d5f | gaqhf | 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 | fa265aca | gaqhf | private static DataTable GetSymbolAttributes() |
145 | 77a33d5f | gaqhf | { |
146 | DataTable dt = new DataTable(); |
||
147 | fa265aca | gaqhf | dt.Columns.Add("Name", typeof(string)); |
148 | dt.Columns.Add("DisplayType", typeof(string)); |
||
149 | dt.Columns.Add("Value", typeof(string)); |
||
150 | dt.Columns.Add("DisplayMember", typeof(string)); |
||
151 | 7a56b228 | gaqhf | |
152 | 77a33d5f | gaqhf | #region UDA |
153 | DataTable udaDT = Project_DB.SelectUDADetails(); |
||
154 | udaDT = udaDT.DefaultView.ToTable(true, "UDAName"); |
||
155 | fa265aca | gaqhf | string display = "User Defined Attribute"; |
156 | 77a33d5f | gaqhf | foreach (DataRow item in udaDT.Rows) |
157 | fa265aca | gaqhf | { |
158 | string name = (string)item["UDAName"]; |
||
159 | string value = item["UDAName"] + "|UDA"; |
||
160 | string displayMember = name + " | " + display; |
||
161 | dt.Rows.Add(name, display, value, displayMember); |
||
162 | } |
||
163 | |||
164 | 77a33d5f | gaqhf | #endregion |
165 | |||
166 | return dt; |
||
167 | } |
||
168 | fa265aca | gaqhf | private static DataTable GetPipeAttributes() |
169 | { |
||
170 | DataTable dt = new DataTable(); |
||
171 | dt.Columns.Add("Name", typeof(string)); |
||
172 | dt.Columns.Add("DisplayType", typeof(string)); |
||
173 | dt.Columns.Add("Value", typeof(string)); |
||
174 | dt.Columns.Add("DisplayMember", typeof(string)); |
||
175 | |||
176 | string display = "Pipe Attribute"; |
||
177 | foreach (var item in PID.Utilities.PipeLabelHelper.GetPipeDisplayLabelFields()) |
||
178 | { |
||
179 | string name = item.Value.FieldName; |
||
180 | string value = item.Key + "|Attribute"; |
||
181 | string displayMember = name + " | " + display; |
||
182 | dt.Rows.Add(name, display, value, displayMember); |
||
183 | } |
||
184 | |||
185 | return dt; |
||
186 | } |
||
187 | public static DataTable GetAPIDAttributes() |
||
188 | { |
||
189 | DataTable attributeTable = new DataTable(); |
||
190 | attributeTable.Columns.Add("Name", typeof(string)); |
||
191 | attributeTable.Columns.Add("DisplayType", typeof(string)); |
||
192 | attributeTable.Columns.Add("Value", typeof(string)); |
||
193 | attributeTable.Columns.Add("DisplayMember", typeof(string)); |
||
194 | |||
195 | attributeTable.Merge(GetSymbolAttributes()); |
||
196 | attributeTable.Merge(GetPipeAttributes()); |
||
197 | 77a33d5f | gaqhf | |
198 | fa265aca | gaqhf | |
199 | return attributeTable; |
||
200 | } |
||
201 | 32954c7f | gaqhf | #endregion |
202 | 4e320fcb | gaqhf | } |
203 | } |