프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ b7a29053

이력 | 보기 | 이력해설 | 다운로드 (15.4 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 65881d60 gaqhf
        public ConverterDocking()
34
        {
35
            InitializeComponent();
36 4941f5fe gaqhf
37
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
38
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
39
            application = wApp.RADApplication;
40 d4c3e39f gaqhf
            
41 4941f5fe gaqhf
            ReleaseCOMObjects(dApplication);
42
            dApplication = null;
43 6a7573b0 gaqhf
            try
44
            {
45
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
46
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
47 154d8f43 gaqhf
48
                Project_Info _ProjectInfo = Project_Info.GetInstance();
49
                _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
50 6a7573b0 gaqhf
            }
51
            catch (Exception ex)
52
            {
53
                StringBuilder sb = new StringBuilder();
54
                sb.AppendLine(ex.Message);
55
                sb.AppendLine(ex.StackTrace);
56
                MessageBox.Show(sb.ToString());
57
            }
58 65881d60 gaqhf
        }
59
60 5a9396ae humkyung
        /// <summary>
61
        /// 선택한 도면들을 읽어서 SPPID로 변환한다.
62
        /// </summary>
63
        /// <param name="sender"></param>
64
        /// <param name="e"></param>
65 e3e2d41f gaqhf
        private void btnConverter_Click(object sender, EventArgs e)
66 65881d60 gaqhf
        {
67 1ba9c671 gaqhf
            ConverterForm converterForm = new ConverterForm();
68
            if (converterForm.ShowDialog() == DialogResult.OK)
69 65881d60 gaqhf
            {
70 4941f5fe gaqhf
                //Ingr.RAD2D.Document doc = application.Documents.Add();
71
72 1ba9c671 gaqhf
                try
73
                {
74
                    CloseOPCForm.Run();
75 ca214bc3 gaqhf
76 d5ec4d0f gaqhf
                    for (int i = 0; i < converterForm.Documents.Count; i++)
77 1ba9c671 gaqhf
                    {
78 d5ec4d0f gaqhf
                        SPPID_Document document = converterForm.Documents[i];
79 1ba9c671 gaqhf
                        if (document.SetSPPIDMapping() && document.Enable)
80
                        {
81 bccacd6c gaqhf
                            using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked))
82 5a9396ae humkyung
                            {
83
                                modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
84
                                modeling.Run();
85
                            }
86 1ba9c671 gaqhf
                        }
87
                    }
88
                }
89
                catch (Exception ex)
90
                {
91
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
92
                }
93
                finally
94 d19ae675 gaqhf
                {
95 1ba9c671 gaqhf
                    CloseOPCForm.Stop();
96 4941f5fe gaqhf
97
                    //doc.SaveOnClose = false;
98
                    //doc.Close(false);
99
100
                    //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
101
                    //dApplication.Drawings[1].CloseDrawing(false);
102
                    //ReleaseCOMObjects(dApplication);
103
                    //dApplication = null;
104 1ba9c671 gaqhf
                }
105
106
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
107
            }
108
        }
109
110 69b7387a gaqhf
        private void btnLinkOPC_Click(object sender, EventArgs e)
111
        {
112 154d8f43 gaqhf
            DataTable tOPCInfo = Project_DB.SelectOPCInfo();
113
            DataTable tOPCRelations = Project_DB.SelectOPCRelations();
114
            DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
115
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
116
117
            foreach (DataRow row in tOPCInfo.Rows)
118
            {
119
                if (!Convert.ToBoolean(row["PAIRED"]))
120
                {
121
                    string drawingUID = row["ID2_DRAWING_UID"].ToString();
122
                    string OPCUID = row["ID2_OPC_UID"].ToString();
123
                    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));
124 69b7387a gaqhf
125 154d8f43 gaqhf
                    if (rows.Length == 2)
126
                    {
127
                        string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
128
                        string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
129
                        string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
130
                        string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
131
                        string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
132
                        string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
133
                        string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
134
                        string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
135
136
                        DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
137
                        DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
138
139
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1)
140
                        {
141
                            DataRow fromOPCInfoRow = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1))[0];
142
                            DataRow toOPCInfoRow = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1))[0];
143
                            string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
144
                            string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
145
                            string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
146 b7a29053 gaqhf
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTYES"].ToString());
147
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
148 154d8f43 gaqhf
                            if (opc.Run())
149
                            {
150
                                fromOPCInfoRow["PAIRED"] = true;
151
                                toOPCInfoRow["PAIRED"] = true;
152
153
                                Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
154
                                Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
155
                            }
156
                            break;
157
                        }
158
                    }
159
                }
160
            }
161
162
            tOPCInfo.Dispose();
163
            tOPCRelations.Dispose();
164
            tDrawingInfo.Dispose();
165
            ReleaseCOMObjects(dApplication);
166
            dApplication = null;
167 4941f5fe gaqhf
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
168
            //WrapperApplication wApp = new WrapperApplication(application.Application);
169
            //Ingr.RAD2D.Application radApp = wApp.RADApplication;
170 e8536f2b gaqhf
171 4941f5fe gaqhf
            //LMADataSource dataSource = new LMADataSource();
172
            //LMDrawings drawings = new LMDrawings();
173 69b7387a gaqhf
174 4941f5fe gaqhf
            ////try
175
            //{
176
            //    Project_Info _ProjectInfo = Project_Info.GetInstance();
177
            //    _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
178
            //    if (Project_DB.ConnTestAndCreateTable())
179
            //    {
180
            //        DataTable dt = Project_DB.SelectSPPID_DB_INFO();
181
            //        if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
182
            //            SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
183
            //        else
184
            //            SPPID_DBInfo.Clear();
185
186
            //        SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance();
187
            //        if (sPPID_DBInfo.Enable)
188
            //        {
189
            //            drawings.Collect(dataSource);
190
191
            //            DataTable drawingTable = Project_DB.SelectDrawingInfo();
192
            //            drawingTable.Columns.Add("EXIST", typeof(bool));
193
            //            drawingTable.Columns.Add("SPPIDPATH", typeof(string));
194
195
            //            foreach (LMDrawing item in drawings)
196
            //            {
197
            //                DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value()));
198
            //                foreach (DataRow row in rows)
199
            //                {
200
            //                    row["EXIST"] = true;
201
            //                    row["DRAWINGNAME"] = item.Attributes["Name"].get_Value();
202
            //                    row["SPPIDPATH"] = item.get_Path();
203
            //                }
204
            //            }
205
206
            //            List<SPPID_Document> allDocuments = new List<SPPID_Document>();
207
            //            foreach (DataRow row in drawingTable.Rows)
208
            //                allDocuments.Add((SPPID_Document)row["DOCUMENT"]);
209
210
            //            AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp);
211
            //            opc.Run();
212
            //        }
213
            //    }
214
            //    else
215
            //    {
216
            //        MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
217
            //    }
218
            //}
219
            ////catch (Exception ex)
220
            //{
221
            //    //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
222
            //}
223
            ////finally
224
            //{
225
            //    ReleaseCOMObjects(dataSource);
226
            //    ReleaseCOMObjects(drawings);
227
            //}
228 69b7387a gaqhf
        }
229
230 4fb0f8d5 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
231
        {
232
            int intNewRefCount = 0;
233
            foreach (object obj in objVars)
234
            {
235
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
236
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
237
            }
238
        }
239
240 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
241 1ba9c671 gaqhf
        {
242 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
243
            WrapperApplication wApp = new WrapperApplication(application.Application);
244
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
245
246 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
247 65881d60 gaqhf
            {
248 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
249
                if (line2D != null)
250 1ba9c671 gaqhf
                {
251 6a7573b0 gaqhf
                    double minX = 0;
252
                    double minY = 0;
253
                    double maxX = 0;
254
                    double maxY = 0;
255
                    line2D.Range(out minX, out minY, out maxX, out maxY);
256
257
                    Settings.Default.DrawingX = maxX - minX;
258
                    Settings.Default.DrawingY = maxY - minY;
259
                    Settings.Default.Save();
260
261
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
262
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
263 1ba9c671 gaqhf
                }
264 6a7573b0 gaqhf
                else
265
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
266 65881d60 gaqhf
            }
267 6a7573b0 gaqhf
            else
268
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
269
        }
270 7e4a64a3 gaqhf
271
        #region TEST
272 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
273
        {
274 154d8f43 gaqhf
            return;
275 4941f5fe gaqhf
            Thread outThread = new Thread(func2 =>
276
            {
277
                for (int i = 100; i < 120; i++)
278
                {
279
                    Thread thread = new Thread(func =>
280
                    {
281
                        dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
282
                        //WrapperApplication wApp = new WrapperApplication(application.Application);
283
                        //Ingr.RAD2D.Application radApp = wApp.RADApplication;
284
                        dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123");
285
286
                        Thread.Sleep(5000);
287
288
                        drawing.CloseDrawing(true);
289
290
                        //application.Quit();
291
                        ReleaseCOMObjects(application);
292
                        application = null;
293
                        ReleaseCOMObjects(drawing);
294
                        drawing = null;
295
                        Thread.Sleep(5000);
296
                    });
297
                    thread.Start();
298
                    thread.Join();
299
                }
300
            });
301
            outThread.Start();
302
            
303
            
304
305 32205389 gaqhf
306 ca6e0f51 gaqhf
307 4941f5fe gaqhf
            //radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid");
308
309
            //radApp.ActiveDocument.Close(true);
310
            //drawing.CloseDrawing(true);
311
312
            //ReleaseCOMObjects(application);
313
            //ReleaseCOMObjects(drawing);
314
            //application = null;
315
            //wApp = null;
316
            //radApp = null;
317
            //drawing = null;
318 ca6e0f51 gaqhf
        }
319 4941f5fe gaqhf
320 ca6e0f51 gaqhf
        private void AutoJoinPipeRun()
321
        {
322 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
323
            WrapperApplication wApp = new WrapperApplication(application.Application);
324
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
325
326 ca6e0f51 gaqhf
            string modelItemId = null;
327
            List<double[]> vertices = new List<double[]>();
328 a31a512e gaqhf
            if (radApp.ActiveSelectSet.Count == 0)
329
            {
330
                return;
331
            }
332 ca6e0f51 gaqhf
            dynamic OID = radApp.ActiveSelectSet[0].Key();
333
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
334
            foreach (var attributes in drawingObject.AttributeSets)
335 4ba01591 gaqhf
            {
336 ca6e0f51 gaqhf
                foreach (var attribute in attributes)
337 4ba01591 gaqhf
                {
338 ca6e0f51 gaqhf
                    if (attribute.Name == "ModelID")
339
                        modelItemId = attribute.GetValue().ToString();
340
                }
341
            }
342
            radApp.ActiveSelectSet.RemoveAll();
343 32205389 gaqhf
344 7e4a64a3 gaqhf
        }
345
        #endregion
346
347 7aee331b gaqhf
348 9628f54b gaqhf
        [DllImport("user32.dll")]
349
        public static extern int FindWindow(string lpClassName, string lpWindowName);
350 3734dcc5 gaqhf
351
        [DllImport("user32.dll", SetLastError = true)]
352
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
353
354 b427ebf9 humkyung
        private void ConverterDocking_Load(object sender, EventArgs e)
355
        {
356
#if DEBUG
357
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
358
#else
359
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
360
#endif
361
362
        }
363 65881d60 gaqhf
    }
364
}
클립보드 이미지 추가 (최대 크기: 500 MB)