hytos / DTI_PID / APIDConverter / Utils / APIDUtils.cs @ 4d9163f7
이력 | 보기 | 이력해설 | 다운로드 (6.27 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 | d03dde83 | gaqhf | |
10 | using Autodesk.AutoCAD.ApplicationServices; |
||
11 | using Autodesk.AutoCAD.ApplicationServices.Core; |
||
12 | using Autodesk.AutoCAD.DatabaseServices; |
||
13 | 14540282 | gaqhf | using Autodesk.AutoCAD.EditorInput; |
14 | d03dde83 | gaqhf | using Autodesk.AutoCAD.Geometry; |
15 | using Autodesk.AutoCAD.Interop; |
||
16 | using Autodesk.AutoCAD.Interop.Common; |
||
17 | using Autodesk.AutoCAD.Runtime; |
||
18 | using Autodesk.AutoCAD.Windows; |
||
19 | 59184d1b | gaqhf | |
20 | using AVEVA.PID.Components; |
||
21 | using AVEVA.PID.GUI; |
||
22 | using AVEVA.PID.Common; |
||
23 | using AVEVA.PID.DWGSelector; |
||
24 | 4e320fcb | gaqhf | |
25 | 5aec7e24 | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
26 | using AVEVA.PID.CustomizationUtility.Model; |
||
27 | using AVEVA.PID.CustomizationUtility.Properties; |
||
28 | |||
29 | 4e320fcb | gaqhf | namespace AVEVA.PID.CustomizationUtility |
30 | { |
||
31 | public class APIDUtils |
||
32 | { |
||
33 | 32954c7f | gaqhf | #region APID Converter |
34 | d03dde83 | gaqhf | public static object FindObjectByUID(Model.Document document, string UID) |
35 | 5aec7e24 | gaqhf | { |
36 | if (!string.IsNullOrEmpty(UID) && UID != "None") |
||
37 | { |
||
38 | foreach (PlantItem item in document.PlantItems) |
||
39 | { |
||
40 | if (item.UID == UID) |
||
41 | return item; |
||
42 | } |
||
43 | } |
||
44 | 4e320fcb | gaqhf | |
45 | 5aec7e24 | gaqhf | return null; |
46 | } |
||
47 | 32954c7f | gaqhf | public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
48 | { |
||
49 | try |
||
50 | { |
||
51 | string[] pointArr = sPoint.Split(new char[] { ',' }); |
||
52 | if (pointArr.Length == 2) |
||
53 | { |
||
54 | dX = Convert.ToDouble(pointArr[0]); |
||
55 | dY = Convert.ToDouble(pointArr[1]); |
||
56 | } |
||
57 | } |
||
58 | d03dde83 | gaqhf | catch (System.Exception) |
59 | 32954c7f | gaqhf | { |
60 | dX = 0; |
||
61 | dY = 0; |
||
62 | return false; |
||
63 | } |
||
64 | |||
65 | return true; |
||
66 | } |
||
67 | d03dde83 | gaqhf | public static bool IsConnectedLine(Model.Line line1, Model.Line line2) |
68 | 53344e2c | gaqhf | { |
69 | bool result = false; |
||
70 | |||
71 | if (line1.CONNECTORS.Find(x => x.ConnectedObject == line2) != null && |
||
72 | line2.CONNECTORS.Find(x => x.ConnectedObject == line1) != null) |
||
73 | result = true; |
||
74 | |||
75 | return result; |
||
76 | } |
||
77 | 016701e5 | gaqhf | public static SlopeType CalcSlope(double x1, double y1, double x2, double y2) |
78 | { |
||
79 | if (x1 - x2 == 0) |
||
80 | return SlopeType.VERTICAL; |
||
81 | else |
||
82 | { |
||
83 | double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
||
84 | if (angle <= 15) |
||
85 | return SlopeType.HORIZONTAL; |
||
86 | else if (angle >= 75) |
||
87 | return SlopeType.VERTICAL; |
||
88 | else |
||
89 | return SlopeType.Slope; |
||
90 | } |
||
91 | } |
||
92 | 32954c7f | gaqhf | #endregion |
93 | 88cb9898 | gaqhf | |
94 | 32954c7f | gaqhf | #region Only AVEVA |
95 | 88cb9898 | gaqhf | public static void SetAvevaExplorer() |
96 | { |
||
97 | bool exist = false; |
||
98 | string sName = "APID Converter"; |
||
99 | for (int i = 0; i < Aveva.Command.AvevaCommands.projectExplorer.Count; i++) |
||
100 | { |
||
101 | if (Aveva.Command.AvevaCommands.projectExplorer[i].Name == sName) |
||
102 | { |
||
103 | exist = true; |
||
104 | Aveva.Command.AvevaCommands.projectExplorer.Remove(i); |
||
105 | break; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | if (!exist) |
||
110 | { |
||
111 | Aveva.Command.AvevaCommands.projectExplorer.Add(sName, new APIDConverterExplorer()); |
||
112 | Aveva.Command.AvevaCommands.projectExplorer.Activate(Aveva.Command.AvevaCommands.projectExplorer.Count - 1); |
||
113 | } |
||
114 | 9ee9b61d | gaqhf | } |
115 | public static List<string> GetPipeStyle() |
||
116 | { |
||
117 | List<string> list = new List<string>(); |
||
118 | Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL"); |
||
119 | object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE"); |
||
120 | if (objPipeStyle != null) |
||
121 | { |
||
122 | Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
||
123 | foreach (var item in pipeStyleCombo.Items) |
||
124 | { |
||
125 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
126 | list.Add(loop.AutomationName); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | return list; |
||
131 | } |
||
132 | public static List<string> GetSignalStyle() |
||
133 | { |
||
134 | List<string> list = new List<string>(); |
||
135 | Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_SIGNAL_PANEL"); |
||
136 | object objPipeStyle = GUIUtils.FindItem(items, "SIGNALSTYLE"); |
||
137 | if (objPipeStyle != null) |
||
138 | { |
||
139 | Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
||
140 | foreach (var item in pipeStyleCombo.Items) |
||
141 | { |
||
142 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
143 | list.Add(loop.AutomationName); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return list; |
||
148 | 88cb9898 | gaqhf | } |
149 | d03dde83 | gaqhf | public static Entity GetEntityByHandle(long handle) |
150 | { |
||
151 | Entity entity = null; |
||
152 | ObjectId objectId = GetObjectIdByHandle(handle); |
||
153 | if (objectId != ObjectId.Null) |
||
154 | { |
||
155 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
156 | Database acCurDb = acDoc.Database; |
||
157 | using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) |
||
158 | { |
||
159 | entity = (Entity)acTrans.GetObject(objectId, OpenMode.ForRead); |
||
160 | acTrans.Commit(); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | return entity; |
||
165 | } |
||
166 | public static ObjectId GetObjectIdByHandle(long lHandle) |
||
167 | { |
||
168 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
169 | Database acCurDb = acDoc.Database; |
||
170 | Handle handle = new Handle(lHandle); |
||
171 | ObjectId result = ObjectId.Null; |
||
172 | try |
||
173 | { |
||
174 | result = acCurDb.GetObjectId(false, handle, 0); |
||
175 | } |
||
176 | catch (System.Exception ex) |
||
177 | { |
||
178 | |||
179 | } |
||
180 | return result; |
||
181 | } |
||
182 | 32954c7f | gaqhf | #endregion |
183 | 4e320fcb | gaqhf | } |
184 | } |