hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 1b09fe17
이력 | 보기 | 이력해설 | 다운로드 (16.9 KB)
1 | 65881d60 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Drawing; |
||
5 | using System.Data; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Threading.Tasks; |
||
9 | using System.Windows.Forms; |
||
10 | using System.Threading; |
||
11 | 69b7387a | gaqhf | using System.IO; |
12 | 65881d60 | gaqhf | using Microsoft.VisualBasic; |
13 | e3e2d41f | gaqhf | using Ingr.RAD2D; |
14 | d19ae675 | gaqhf | using Converter.BaseModel; |
15 | using Converter.SPPID.Properties; |
||
16 | using Converter.SPPID.DB; |
||
17 | using Converter.SPPID.Util; |
||
18 | using Converter.SPPID.Form; |
||
19 | using Converter.SPPID.Model; |
||
20 | 1ba9c671 | gaqhf | using Plaice; |
21 | using Llama; |
||
22 | ca214bc3 | gaqhf | using DevExpress.XtraSplashScreen; |
23 | 224535bb | gaqhf | using Newtonsoft.Json; |
24 | 9628f54b | gaqhf | using System.Runtime.InteropServices; |
25 | 4941f5fe | gaqhf | using System.Reflection; |
26 | 154d8f43 | gaqhf | using Converter.SPPID.OPC; |
27 | 65881d60 | gaqhf | |
28 | namespace Converter.SPPID.Wrapper |
||
29 | { |
||
30 | public partial class ConverterDocking : UserControl |
||
31 | { |
||
32 | 4941f5fe | gaqhf | Ingr.RAD2D.Application application; |
33 | f14b4e3b | gaqhf | static bool addEvent = false; |
34 | 65881d60 | gaqhf | public ConverterDocking() |
35 | { |
||
36 | InitializeComponent(); |
||
37 | 4941f5fe | gaqhf | |
38 | dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
39 | WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
||
40 | application = wApp.RADApplication; |
||
41 | d4c3e39f | gaqhf | |
42 | 4941f5fe | gaqhf | ReleaseCOMObjects(dApplication); |
43 | dApplication = null; |
||
44 | 6a7573b0 | gaqhf | try |
45 | { |
||
46 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
47 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
48 | 154d8f43 | gaqhf | |
49 | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
||
50 | 8847ea67 | gaqhf | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
51 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
52 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
53 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
54 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
55 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
56 | f14b4e3b | gaqhf | |
57 | if (!addEvent) |
||
58 | { |
||
59 | application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit; |
||
60 | 70b0b5d7 | gaqhf | RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode()); |
61 | f14b4e3b | gaqhf | addEvent = true; |
62 | } |
||
63 | 6a7573b0 | gaqhf | } |
64 | catch (Exception ex) |
||
65 | { |
||
66 | StringBuilder sb = new StringBuilder(); |
||
67 | sb.AppendLine(ex.Message); |
||
68 | sb.AppendLine(ex.StackTrace); |
||
69 | MessageBox.Show(sb.ToString()); |
||
70 | } |
||
71 | 65881d60 | gaqhf | } |
72 | 1b09fe17 | gaqhf | private void ApplicationEvents_ApplicationExit(out bool cancel) |
73 | { |
||
74 | UnregisterHotKey(this.Handle, 0); |
||
75 | cancel = false; |
||
76 | } |
||
77 | 65881d60 | gaqhf | |
78 | 5a9396ae | humkyung | /// <summary> |
79 | /// 선택한 도면들을 읽어서 SPPID로 변환한다. |
||
80 | /// </summary> |
||
81 | /// <param name="sender"></param> |
||
82 | /// <param name="e"></param> |
||
83 | e3e2d41f | gaqhf | private void btnConverter_Click(object sender, EventArgs e) |
84 | 65881d60 | gaqhf | { |
85 | 1ba9c671 | gaqhf | ConverterForm converterForm = new ConverterForm(); |
86 | if (converterForm.ShowDialog() == DialogResult.OK) |
||
87 | 65881d60 | gaqhf | { |
88 | 4941f5fe | gaqhf | //Ingr.RAD2D.Document doc = application.Documents.Add(); |
89 | |||
90 | 1ba9c671 | gaqhf | try |
91 | { |
||
92 | CloseOPCForm.Run(); |
||
93 | ca214bc3 | gaqhf | |
94 | d5ec4d0f | gaqhf | for (int i = 0; i < converterForm.Documents.Count; i++) |
95 | 1ba9c671 | gaqhf | { |
96 | d5ec4d0f | gaqhf | SPPID_Document document = converterForm.Documents[i]; |
97 | 1ba9c671 | gaqhf | if (document.SetSPPIDMapping() && document.Enable) |
98 | { |
||
99 | bccacd6c | gaqhf | using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
100 | 5a9396ae | humkyung | { |
101 | modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
||
102 | modeling.Run(); |
||
103 | } |
||
104 | 1ba9c671 | gaqhf | } |
105 | } |
||
106 | } |
||
107 | catch (Exception ex) |
||
108 | { |
||
109 | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
110 | } |
||
111 | finally |
||
112 | d19ae675 | gaqhf | { |
113 | 1ba9c671 | gaqhf | CloseOPCForm.Stop(); |
114 | 4941f5fe | gaqhf | |
115 | //doc.SaveOnClose = false; |
||
116 | //doc.Close(false); |
||
117 | |||
118 | //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
119 | //dApplication.Drawings[1].CloseDrawing(false); |
||
120 | //ReleaseCOMObjects(dApplication); |
||
121 | //dApplication = null; |
||
122 | 1ba9c671 | gaqhf | } |
123 | |||
124 | MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | 69b7387a | gaqhf | private void btnLinkOPC_Click(object sender, EventArgs e) |
129 | { |
||
130 | 154d8f43 | gaqhf | DataTable tOPCInfo = Project_DB.SelectOPCInfo(); |
131 | DataTable tOPCRelations = Project_DB.SelectOPCRelations(); |
||
132 | DataTable tDrawingInfo = Project_DB.SelectDrawingInfo(); |
||
133 | dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
||
134 | |||
135 | foreach (DataRow row in tOPCInfo.Rows) |
||
136 | { |
||
137 | if (!Convert.ToBoolean(row["PAIRED"])) |
||
138 | { |
||
139 | string drawingUID = row["ID2_DRAWING_UID"].ToString(); |
||
140 | string OPCUID = row["ID2_OPC_UID"].ToString(); |
||
141 | DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID)); |
||
142 | 69b7387a | gaqhf | |
143 | 154d8f43 | gaqhf | if (rows.Length == 2) |
144 | { |
||
145 | string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString(); |
||
146 | string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString(); |
||
147 | string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString(); |
||
148 | string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString(); |
||
149 | string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString(); |
||
150 | string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString(); |
||
151 | string toOPCUID1 = rows[0]["To_OPC_UID"].ToString(); |
||
152 | string toOPCUID2 = rows[1]["To_OPC_UID"].ToString(); |
||
153 | |||
154 | DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1)); |
||
155 | DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1)); |
||
156 | 58993ba9 | gaqhf | DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1)); |
157 | DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1)); |
||
158 | 154d8f43 | gaqhf | |
159 | 58993ba9 | gaqhf | if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1) |
160 | 154d8f43 | gaqhf | { |
161 | 58993ba9 | gaqhf | DataRow fromOPCInfoRow = fromOPCInfoRows[0]; |
162 | DataRow toOPCInfoRow = toOPCInfoRows[0]; |
||
163 | 154d8f43 | gaqhf | string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
164 | string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(); |
||
165 | string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString(); |
||
166 | 58993ba9 | gaqhf | List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString()); |
167 | b7a29053 | gaqhf | AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes); |
168 | 154d8f43 | gaqhf | if (opc.Run()) |
169 | { |
||
170 | fromOPCInfoRow["PAIRED"] = true; |
||
171 | toOPCInfoRow["PAIRED"] = true; |
||
172 | |||
173 | Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
||
174 | Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true); |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | |||
181 | tOPCInfo.Dispose(); |
||
182 | tOPCRelations.Dispose(); |
||
183 | tDrawingInfo.Dispose(); |
||
184 | ReleaseCOMObjects(dApplication); |
||
185 | dApplication = null; |
||
186 | 58993ba9 | gaqhf | |
187 | MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
188 | 69b7387a | gaqhf | } |
189 | |||
190 | 4fb0f8d5 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
191 | { |
||
192 | int intNewRefCount = 0; |
||
193 | foreach (object obj in objVars) |
||
194 | { |
||
195 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
196 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | 6a7573b0 | gaqhf | private void btnGetDrawingSize_Click(object sender, EventArgs e) |
201 | 1ba9c671 | gaqhf | { |
202 | d4c3e39f | gaqhf | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
203 | WrapperApplication wApp = new WrapperApplication(application.Application); |
||
204 | Ingr.RAD2D.Application radApp = wApp.RADApplication; |
||
205 | |||
206 | 6a7573b0 | gaqhf | if (radApp.ActiveSelectSet.Count > 0) |
207 | 65881d60 | gaqhf | { |
208 | 6a7573b0 | gaqhf | DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
209 | if (line2D != null) |
||
210 | 1ba9c671 | gaqhf | { |
211 | 6a7573b0 | gaqhf | double minX = 0; |
212 | double minY = 0; |
||
213 | double maxX = 0; |
||
214 | double maxY = 0; |
||
215 | line2D.Range(out minX, out minY, out maxX, out maxY); |
||
216 | |||
217 | Settings.Default.DrawingX = maxX - minX; |
||
218 | Settings.Default.DrawingY = maxY - minY; |
||
219 | Settings.Default.Save(); |
||
220 | |||
221 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
222 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
223 | 1ba9c671 | gaqhf | } |
224 | 6a7573b0 | gaqhf | else |
225 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
226 | 65881d60 | gaqhf | } |
227 | 6a7573b0 | gaqhf | else |
228 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
229 | } |
||
230 | 7e4a64a3 | gaqhf | |
231 | 1b09fe17 | gaqhf | #region Hot Key |
232 | 70b0b5d7 | gaqhf | [System.Runtime.InteropServices.DllImport("user32.dll")] |
233 | private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); |
||
234 | |||
235 | [System.Runtime.InteropServices.DllImport("user32.dll")] |
||
236 | private static extern bool UnregisterHotKey(IntPtr hWnd, int id); |
||
237 | |||
238 | enum KeyModifier |
||
239 | { |
||
240 | None = 0, |
||
241 | Alt = 1, |
||
242 | Control = 2, |
||
243 | Shift = 4, |
||
244 | WinKey = 8 |
||
245 | } |
||
246 | |||
247 | protected override void WndProc(ref Message m) |
||
248 | { |
||
249 | base.WndProc(ref m); |
||
250 | if (m.Msg == 0x0312) |
||
251 | { |
||
252 | Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); |
||
253 | KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF); |
||
254 | int id = m.WParam.ToInt32(); |
||
255 | application.RunCommand(CommandConstants.igcmdGridSnap); |
||
256 | } |
||
257 | |||
258 | } |
||
259 | 1b09fe17 | gaqhf | #endregion |
260 | 70b0b5d7 | gaqhf | |
261 | 1b09fe17 | gaqhf | #region TEST |
262 | f14b4e3b | gaqhf | |
263 | 6a7573b0 | gaqhf | private void simpleButton1_Click(object sender, EventArgs e) |
264 | { |
||
265 | b7b123ba | gaqhf | Placement placement = new Placement(); |
266 | if (application.ActiveSelectSet.Count > 0) |
||
267 | d9fc7084 | gaqhf | { |
268 | b7b123ba | gaqhf | string modelItemId = null; |
269 | Symbol2d symbol2D = application.ActiveSelectSet[0] as Symbol2d; |
||
270 | DependencyObject dependency = application.ActiveSelectSet[0] as DependencyObject; |
||
271 | application.ActiveSelectSet.RemoveAll(); |
||
272 | if (symbol2D != null) |
||
273 | d9fc7084 | gaqhf | { |
274 | b7b123ba | gaqhf | return; |
275 | foreach (var attributes in symbol2D.AttributeSets) |
||
276 | 90662b0b | gaqhf | { |
277 | b7b123ba | gaqhf | foreach (var attribute in attributes) |
278 | { |
||
279 | if (attribute.Name == "ModelID") |
||
280 | modelItemId = attribute.GetValue().ToString(); |
||
281 | } |
||
282 | 90662b0b | gaqhf | } |
283 | |||
284 | b7b123ba | gaqhf | if (modelItemId!=null) |
285 | { |
||
286 | e0828ff4 | gaqhf | LMADataSource dataSource = new LMADataSource(); |
287 | b7b123ba | gaqhf | LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
288 | foreach (LMRepresentation item in modelItem.Representations) |
||
289 | { |
||
290 | if (item.ModelItemID == modelItemId) |
||
291 | { |
||
292 | dataSource = placement.PIDDataSource; |
||
293 | LMSymbol symbol = dataSource.GetSymbol(item.Id); |
||
294 | double oldx = symbol.get_XCoordinate(); |
||
295 | double oldy = symbol.get_YCoordinate(); |
||
296 | symbol2D.Move(0, 0, 0, GridSetting.GetInstance().Length); |
||
297 | |||
298 | dataSource = new LMADataSource(); |
||
299 | //dataSource = placement.PIDDataSource; |
||
300 | symbol = dataSource.GetSymbol(item.Id); |
||
301 | double x = symbol.get_XCoordinate(); |
||
302 | double y = symbol.get_YCoordinate(); |
||
303 | } |
||
304 | } |
||
305 | } |
||
306 | 4e865771 | gaqhf | } |
307 | b7b123ba | gaqhf | else if (dependency != null) |
308 | 4e865771 | gaqhf | { |
309 | b7b123ba | gaqhf | foreach (dynamic item in dependency.DrawingObjects) |
310 | { |
||
311 | item.Move(0, 0, 0, GridSetting.GetInstance().Length); |
||
312 | } |
||
313 | d9fc7084 | gaqhf | } |
314 | } |
||
315 | 4e865771 | gaqhf | |
316 | 154d8f43 | gaqhf | return; |
317 | 4941f5fe | gaqhf | Thread outThread = new Thread(func2 => |
318 | { |
||
319 | for (int i = 100; i < 120; i++) |
||
320 | { |
||
321 | Thread thread = new Thread(func => |
||
322 | { |
||
323 | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
||
324 | //WrapperApplication wApp = new WrapperApplication(application.Application); |
||
325 | //Ingr.RAD2D.Application radApp = wApp.RADApplication; |
||
326 | dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123"); |
||
327 | |||
328 | Thread.Sleep(5000); |
||
329 | |||
330 | drawing.CloseDrawing(true); |
||
331 | |||
332 | //application.Quit(); |
||
333 | ReleaseCOMObjects(application); |
||
334 | application = null; |
||
335 | ReleaseCOMObjects(drawing); |
||
336 | drawing = null; |
||
337 | Thread.Sleep(5000); |
||
338 | }); |
||
339 | thread.Start(); |
||
340 | thread.Join(); |
||
341 | } |
||
342 | }); |
||
343 | outThread.Start(); |
||
344 | |||
345 | |||
346 | |||
347 | 32205389 | gaqhf | |
348 | ca6e0f51 | gaqhf | |
349 | 4941f5fe | gaqhf | //radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid"); |
350 | |||
351 | //radApp.ActiveDocument.Close(true); |
||
352 | //drawing.CloseDrawing(true); |
||
353 | |||
354 | //ReleaseCOMObjects(application); |
||
355 | //ReleaseCOMObjects(drawing); |
||
356 | //application = null; |
||
357 | //wApp = null; |
||
358 | //radApp = null; |
||
359 | //drawing = null; |
||
360 | ca6e0f51 | gaqhf | } |
361 | 4941f5fe | gaqhf | |
362 | ca6e0f51 | gaqhf | private void AutoJoinPipeRun() |
363 | { |
||
364 | d4c3e39f | gaqhf | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
365 | WrapperApplication wApp = new WrapperApplication(application.Application); |
||
366 | Ingr.RAD2D.Application radApp = wApp.RADApplication; |
||
367 | |||
368 | ca6e0f51 | gaqhf | string modelItemId = null; |
369 | List<double[]> vertices = new List<double[]>(); |
||
370 | a31a512e | gaqhf | if (radApp.ActiveSelectSet.Count == 0) |
371 | { |
||
372 | return; |
||
373 | } |
||
374 | ca6e0f51 | gaqhf | dynamic OID = radApp.ActiveSelectSet[0].Key(); |
375 | DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
||
376 | foreach (var attributes in drawingObject.AttributeSets) |
||
377 | 4ba01591 | gaqhf | { |
378 | ca6e0f51 | gaqhf | foreach (var attribute in attributes) |
379 | 4ba01591 | gaqhf | { |
380 | ca6e0f51 | gaqhf | if (attribute.Name == "ModelID") |
381 | modelItemId = attribute.GetValue().ToString(); |
||
382 | } |
||
383 | } |
||
384 | radApp.ActiveSelectSet.RemoveAll(); |
||
385 | 32205389 | gaqhf | |
386 | 7e4a64a3 | gaqhf | } |
387 | #endregion |
||
388 | |||
389 | 7aee331b | gaqhf | |
390 | 9628f54b | gaqhf | [DllImport("user32.dll")] |
391 | public static extern int FindWindow(string lpClassName, string lpWindowName); |
||
392 | 3734dcc5 | gaqhf | |
393 | [DllImport("user32.dll", SetLastError = true)] |
||
394 | static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
||
395 | |||
396 | b427ebf9 | humkyung | private void ConverterDocking_Load(object sender, EventArgs e) |
397 | { |
||
398 | #if DEBUG |
||
399 | this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
||
400 | #else |
||
401 | this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
||
402 | #endif |
||
403 | |||
404 | } |
||
405 | 65881d60 | gaqhf | } |
406 | } |