hytos / DTI_PID / APIDConverter / Utils / APIDUtils.cs @ d8bd4799
이력 | 보기 | 이력해설 | 다운로드 (6.27 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 |
|
10 |
using Autodesk.AutoCAD.ApplicationServices; |
11 |
using Autodesk.AutoCAD.ApplicationServices.Core; |
12 |
using Autodesk.AutoCAD.DatabaseServices; |
13 |
using Autodesk.AutoCAD.EditorInput; |
14 |
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 |
|
20 |
using AVEVA.PID.Components; |
21 |
using AVEVA.PID.GUI; |
22 |
using AVEVA.PID.Common; |
23 |
using AVEVA.PID.DWGSelector; |
24 |
|
25 |
using AVEVA.PID.CustomizationUtility.DB; |
26 |
using AVEVA.PID.CustomizationUtility.Model; |
27 |
using AVEVA.PID.CustomizationUtility.Properties; |
28 |
|
29 |
namespace AVEVA.PID.CustomizationUtility |
30 |
{ |
31 |
public class APIDUtils |
32 |
{ |
33 |
#region APID Converter |
34 |
public static object FindObjectByUID(Model.Document document, string UID) |
35 |
{ |
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 |
|
45 |
return null; |
46 |
} |
47 |
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 |
catch (System.Exception) |
59 |
{ |
60 |
dX = 0; |
61 |
dY = 0; |
62 |
return false; |
63 |
} |
64 |
|
65 |
return true; |
66 |
} |
67 |
public static bool IsConnectedLine(Model.Line line1, Model.Line line2) |
68 |
{ |
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 |
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 |
#endregion |
93 |
|
94 |
#region Only AVEVA |
95 |
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 |
} |
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 |
} |
149 |
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 |
#endregion |
183 |
} |
184 |
} |