프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 147c80c4

이력 | 보기 | 이력해설 | 다운로드 (15 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 58993ba9 gaqhf
                        DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
139
                        DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
140 154d8f43 gaqhf
141 58993ba9 gaqhf
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
142 154d8f43 gaqhf
                        {
143 58993ba9 gaqhf
                            DataRow fromOPCInfoRow = fromOPCInfoRows[0];
144
                            DataRow toOPCInfoRow = toOPCInfoRows[0];
145 154d8f43 gaqhf
                            string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
146
                            string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
147
                            string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
148 58993ba9 gaqhf
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
149 b7a29053 gaqhf
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
150 154d8f43 gaqhf
                            if (opc.Run())
151
                            {
152
                                fromOPCInfoRow["PAIRED"] = true;
153
                                toOPCInfoRow["PAIRED"] = true;
154
155
                                Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
156
                                Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
157
                            }
158
                        }
159
                    }
160
                }
161
            }
162
163
            tOPCInfo.Dispose();
164
            tOPCRelations.Dispose();
165
            tDrawingInfo.Dispose();
166
            ReleaseCOMObjects(dApplication);
167
            dApplication = null;
168 58993ba9 gaqhf
169
            MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
170 69b7387a gaqhf
        }
171
172 4fb0f8d5 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
173
        {
174
            int intNewRefCount = 0;
175
            foreach (object obj in objVars)
176
            {
177
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
178
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
179
            }
180
        }
181
182 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
183 1ba9c671 gaqhf
        {
184 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
185
            WrapperApplication wApp = new WrapperApplication(application.Application);
186
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
187
188 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
189 65881d60 gaqhf
            {
190 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
191
                if (line2D != null)
192 1ba9c671 gaqhf
                {
193 6a7573b0 gaqhf
                    double minX = 0;
194
                    double minY = 0;
195
                    double maxX = 0;
196
                    double maxY = 0;
197
                    line2D.Range(out minX, out minY, out maxX, out maxY);
198
199
                    Settings.Default.DrawingX = maxX - minX;
200
                    Settings.Default.DrawingY = maxY - minY;
201
                    Settings.Default.Save();
202
203
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
204
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
205 1ba9c671 gaqhf
                }
206 6a7573b0 gaqhf
                else
207
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
208 65881d60 gaqhf
            }
209 6a7573b0 gaqhf
            else
210
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
211
        }
212 7e4a64a3 gaqhf
213
        #region TEST
214 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
215
        {
216 a1d82fda gaqhf
            //foreach (RADObject item in application.ActiveDocument.ActiveSheet.DrawingObjects)
217
            //{
218
            //    DependencyObject dependencyObject = item as DependencyObject;
219
            //    if (dependencyObject != null)
220
            //    {
221
            //        foreach (var attributes in dependencyObject.AttributeSets)
222
            //        {
223
            //            foreach (var attribute in attributes)
224
            //            {
225
            //                if (!DBNull.Value.Equals(attribute.GetValue()) && attribute.GetValue() != null && attribute.GetValue().ToString() == "40E2CDE9781940089C37258D37FA3BCD")
226
            //                {
227
            //                    application.ActiveSelectSet.Add(item);
228
            //                }
229
            //            }
230
            //        }
231
            //    }
232
            //}
233
234
            Placement placement = new Placement();
235
            LMADataSource dataSource = placement.PIDDataSource;
236
237
            LMModelItem modelItem = dataSource.GetModelItem("16C45380E2EB4818A6A9BFE11F0228DE");
238
            LMPipeRun pipeRun = dataSource.GetPipeRun("16C45380E2EB4818A6A9BFE11F0228DE");
239
            LMSymbol symbol = dataSource.GetSymbol("F454BD9CC87C4C3AAE8282F2AB10B7E0");
240
            string symbolPath = string.Empty;
241
            if (modelItem != null)
242 d9fc7084 gaqhf
            {
243 a1d82fda gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
244 d9fc7084 gaqhf
                {
245 a1d82fda gaqhf
                    if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
246 d9fc7084 gaqhf
                    {
247 a1d82fda gaqhf
                        symbolPath = rep.get_FileName();
248
                        string newFileName = @"\Piping\Routing\Process Lines\Secondary Piping.sym";
249
                        if (symbolPath != newFileName)
250 d9fc7084 gaqhf
                        {
251 a1d82fda gaqhf
252
                            //symbol.set_FileName(newFileName);
253
                            placement.PIDReplaceSymbol(newFileName, ref symbol);
254
                            symbol.Commit();
255
                            //rep.set_FileName(newFileName);
256
                            //rep.Commit();
257
                            
258 d9fc7084 gaqhf
                        }
259 a1d82fda gaqhf
                        break;
260 d9fc7084 gaqhf
                    }
261
                }
262
            }
263 1299077b gaqhf
264 154d8f43 gaqhf
            return;
265 4941f5fe gaqhf
            Thread outThread = new Thread(func2 =>
266
            {
267
                for (int i = 100; i < 120; i++)
268
                {
269
                    Thread thread = new Thread(func =>
270
                    {
271
                        dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
272
                        //WrapperApplication wApp = new WrapperApplication(application.Application);
273
                        //Ingr.RAD2D.Application radApp = wApp.RADApplication;
274
                        dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123");
275
276
                        Thread.Sleep(5000);
277
278
                        drawing.CloseDrawing(true);
279
280
                        //application.Quit();
281
                        ReleaseCOMObjects(application);
282
                        application = null;
283
                        ReleaseCOMObjects(drawing);
284
                        drawing = null;
285
                        Thread.Sleep(5000);
286
                    });
287
                    thread.Start();
288
                    thread.Join();
289
                }
290
            });
291
            outThread.Start();
292
            
293
            
294
295 32205389 gaqhf
296 ca6e0f51 gaqhf
297 4941f5fe gaqhf
            //radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid");
298
299
            //radApp.ActiveDocument.Close(true);
300
            //drawing.CloseDrawing(true);
301
302
            //ReleaseCOMObjects(application);
303
            //ReleaseCOMObjects(drawing);
304
            //application = null;
305
            //wApp = null;
306
            //radApp = null;
307
            //drawing = null;
308 ca6e0f51 gaqhf
        }
309 4941f5fe gaqhf
310 ca6e0f51 gaqhf
        private void AutoJoinPipeRun()
311
        {
312 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
313
            WrapperApplication wApp = new WrapperApplication(application.Application);
314
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
315
316 ca6e0f51 gaqhf
            string modelItemId = null;
317
            List<double[]> vertices = new List<double[]>();
318 a31a512e gaqhf
            if (radApp.ActiveSelectSet.Count == 0)
319
            {
320
                return;
321
            }
322 ca6e0f51 gaqhf
            dynamic OID = radApp.ActiveSelectSet[0].Key();
323
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
324
            foreach (var attributes in drawingObject.AttributeSets)
325 4ba01591 gaqhf
            {
326 ca6e0f51 gaqhf
                foreach (var attribute in attributes)
327 4ba01591 gaqhf
                {
328 ca6e0f51 gaqhf
                    if (attribute.Name == "ModelID")
329
                        modelItemId = attribute.GetValue().ToString();
330
                }
331
            }
332
            radApp.ActiveSelectSet.RemoveAll();
333 32205389 gaqhf
334 7e4a64a3 gaqhf
        }
335
        #endregion
336
337 7aee331b gaqhf
338 9628f54b gaqhf
        [DllImport("user32.dll")]
339
        public static extern int FindWindow(string lpClassName, string lpWindowName);
340 3734dcc5 gaqhf
341
        [DllImport("user32.dll", SetLastError = true)]
342
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
343
344 b427ebf9 humkyung
        private void ConverterDocking_Load(object sender, EventArgs e)
345
        {
346
#if DEBUG
347
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
348
#else
349
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
350
#endif
351
352
        }
353 65881d60 gaqhf
    }
354
}
클립보드 이미지 추가 (최대 크기: 500 MB)