hytos / DTI_PID / APIDConverter / AutoModeling.cs @ e9c674be
이력 | 보기 | 이력해설 | 다운로드 (7.88 KB)
1 | 74a0c9d6 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Configuration; |
||
4 | using System.Data; |
||
5 | using System.Data.Common; |
||
6 | using System.Data.SqlClient; |
||
7 | using System.IO; |
||
8 | |||
9 | using Autodesk.AutoCAD.ApplicationServices; |
||
10 | using Autodesk.AutoCAD.ApplicationServices.Core; |
||
11 | using Autodesk.AutoCAD.DatabaseServices; |
||
12 | using Autodesk.AutoCAD.EditorInput; |
||
13 | using Autodesk.AutoCAD.Geometry; |
||
14 | using Autodesk.AutoCAD.Interop; |
||
15 | using Autodesk.AutoCAD.Interop.Common; |
||
16 | using Autodesk.AutoCAD.Runtime; |
||
17 | using Autodesk.AutoCAD.Windows; |
||
18 | |||
19 | |||
20 | namespace AVEVA.PID.CustomizationUtility |
||
21 | { |
||
22 | public class AutoModeling |
||
23 | { |
||
24 | Autodesk.Windows.RibbonCombo pipeStyleCombo = null; |
||
25 | 46756c13 | gaqhf | Autodesk.Windows.RibbonCombo signalStyleCombo = null; |
26 | 74a0c9d6 | gaqhf | Autodesk.Windows.RibbonChecklistButton autoLabelCheckListButton = null; |
27 | |||
28 | private void InitGUI() |
||
29 | { |
||
30 | Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL"); |
||
31 | object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE"); |
||
32 | if (objPipeStyle != null) |
||
33 | pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
||
34 | object objAutoLabel = GUIUtils.FindItem(items, "Auto Label"); |
||
35 | if (objAutoLabel != null) |
||
36 | autoLabelCheckListButton = objAutoLabel as Autodesk.Windows.RibbonChecklistButton; |
||
37 | |||
38 | 46756c13 | gaqhf | items = GUI.RibbonHelper.GetPanelItems("ID_SIGNAL_PANEL"); |
39 | object objSignalStyle = GUIUtils.FindItem(items, "SIGNALSTYLE"); |
||
40 | if (objSignalStyle != null) |
||
41 | signalStyleCombo = objSignalStyle as Autodesk.Windows.RibbonCombo; |
||
42 | 74a0c9d6 | gaqhf | } |
43 | private void SetAutoLabelUnCehck() |
||
44 | { |
||
45 | if (autoLabelCheckListButton != null) |
||
46 | { |
||
47 | foreach (var item in autoLabelCheckListButton.Items) |
||
48 | { |
||
49 | if (item.GetType() == typeof(Autodesk.Windows.RibbonButton)) |
||
50 | { |
||
51 | Autodesk.Windows.RibbonButton ribbonButton = item as Autodesk.Windows.RibbonButton; |
||
52 | if (ribbonButton.IsChecked) |
||
53 | ribbonButton.IsChecked = false; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | private void SetPipeStyle(string style) |
||
60 | { |
||
61 | if (pipeStyleCombo.Current != null) |
||
62 | { |
||
63 | Autodesk.Windows.RibbonButton button = pipeStyleCombo.Current as Autodesk.Windows.RibbonButton; |
||
64 | if (button.AutomationName != style) |
||
65 | { |
||
66 | foreach (var item in pipeStyleCombo.Items) |
||
67 | { |
||
68 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
69 | if (loop.AutomationName == style) |
||
70 | { |
||
71 | pipeStyleCombo.Current = loop; |
||
72 | break; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | |||
79 | 46756c13 | gaqhf | private void SetSignalStyle(string style) |
80 | { |
||
81 | if (signalStyleCombo.Current != null) |
||
82 | { |
||
83 | Autodesk.Windows.RibbonButton button = signalStyleCombo.Current as Autodesk.Windows.RibbonButton; |
||
84 | if (button.AutomationName != style) |
||
85 | { |
||
86 | foreach (var item in signalStyleCombo.Items) |
||
87 | { |
||
88 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
89 | if (loop.AutomationName == style) |
||
90 | { |
||
91 | signalStyleCombo.Current = loop; |
||
92 | break; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | 74a0c9d6 | gaqhf | private string ReadDrawingLastLine() |
100 | { |
||
101 | string sHandle = string.Empty; |
||
102 | SqlConnection connection = null; |
||
103 | try |
||
104 | { |
||
105 | connection = new SqlConnection(); |
||
106 | 534ca9c5 | gaqhf | connection.ConnectionString = DB.Project_DB.GetAvevaConnectionString(); |
107 | 74a0c9d6 | gaqhf | connection.Open(); |
108 | |||
109 | string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test"); |
||
110 | SqlCommand cmd = new SqlCommand(); |
||
111 | cmd.Connection = connection; |
||
112 | cmd.CommandText = strQry; |
||
113 | cmd.CommandType = CommandType.Text; |
||
114 | |||
115 | SqlDataAdapter da = new SqlDataAdapter(cmd); |
||
116 | System.Data.DataTable dt = new System.Data.DataTable(); |
||
117 | da.Fill(dt); |
||
118 | if (dt.Rows.Count == 1) |
||
119 | sHandle = dt.Rows[0][0].ToString(); |
||
120 | |||
121 | dt.Dispose(); |
||
122 | da.Dispose(); |
||
123 | } |
||
124 | catch (System.Exception) |
||
125 | { } |
||
126 | finally |
||
127 | { |
||
128 | if (connection != null) |
||
129 | connection.Close(); |
||
130 | } |
||
131 | |||
132 | return sHandle; |
||
133 | } |
||
134 | |||
135 | #region Drawing Method |
||
136 | private string DrawPipe(string style, List<string> coordinates) |
||
137 | { |
||
138 | SetPipeStyle(style); |
||
139 | |||
140 | string prevHandle = ReadDrawingLastLine(); |
||
141 | |||
142 | Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
143 | Editor editor = acDoc.Editor; |
||
144 | List<object> commandParam = new List<object>(); |
||
145 | //command name |
||
146 | commandParam.Add("DRPIPE"); |
||
147 | //coordinate |
||
148 | foreach (var item in coordinates) |
||
149 | commandParam.Add(item); |
||
150 | //enter |
||
151 | commandParam.Add(null); |
||
152 | //enter |
||
153 | commandParam.Add(null); |
||
154 | |||
155 | editor.Command(commandParam.ToArray()); |
||
156 | |||
157 | string newHandle = ReadDrawingLastLine(); |
||
158 | if (prevHandle == newHandle) |
||
159 | return string.Empty; |
||
160 | |||
161 | return newHandle; |
||
162 | } |
||
163 | private void DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
||
164 | { |
||
165 | SetPipeStyle(style); |
||
166 | |||
167 | Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
168 | Editor editor = acDoc.Editor; |
||
169 | List<object> commandParam = new List<object>(); |
||
170 | //command name |
||
171 | commandParam.Add("DRPIPE"); |
||
172 | //coordinate |
||
173 | foreach (var item in coordinates) |
||
174 | commandParam.Add(item); |
||
175 | //enter |
||
176 | commandParam.Add(null); |
||
177 | |||
178 | //Input Object ID |
||
179 | commandParam.Add(objectId); |
||
180 | |||
181 | //enter |
||
182 | commandParam.Add(null); |
||
183 | |||
184 | editor.Command(commandParam.ToArray()); |
||
185 | } |
||
186 | 6b3cb476 | gaqhf | private void InsertSymbol(string insertSymbolName, double x, double y) |
187 | { |
||
188 | try |
||
189 | { |
||
190 | AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
||
191 | drawingData.InsertSymbolName = insertSymbolName; |
||
192 | Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
||
193 | Editor editor = acDoc.Editor; |
||
194 | List<object> commandParam = new List<object>(); |
||
195 | commandParam.Add("INSSYM"); |
||
196 | Point3d point = new Point3d(x, y, 0); |
||
197 | commandParam.Add(point); |
||
198 | commandParam.Add(null); |
||
199 | |||
200 | editor.Command(commandParam.ToArray()); |
||
201 | } |
||
202 | catch (System.Exception ex) |
||
203 | { |
||
204 | 74a0c9d6 | gaqhf | |
205 | 6b3cb476 | gaqhf | } |
206 | } |
||
207 | 74a0c9d6 | gaqhf | #endregion |
208 | |||
209 | #region Test Source |
||
210 | public void test() |
||
211 | { |
||
212 | InitGUI(); |
||
213 | |||
214 | DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }); |
||
215 | |||
216 | DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
||
217 | |||
218 | DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
||
219 | } |
||
220 | |||
221 | public static void TEST() |
||
222 | { |
||
223 | AutoModeling auto = new AutoModeling(); |
||
224 | auto.test(); |
||
225 | } |
||
226 | #endregion |
||
227 | } |
||
228 | } |