프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 0cab8feb

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