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