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