프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 4941f5fe

이력 | 보기 | 이력해설 | 다운로드 (11.2 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 65881d60 gaqhf
27
namespace Converter.SPPID.Wrapper
28
{
29
    public partial class ConverterDocking : UserControl
30
    {
31 4941f5fe gaqhf
        Ingr.RAD2D.Application application;
32 65881d60 gaqhf
        public ConverterDocking()
33
        {
34
            InitializeComponent();
35 4941f5fe gaqhf
36
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
37
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
38
            application = wApp.RADApplication;
39 d4c3e39f gaqhf
            
40 4941f5fe gaqhf
            ReleaseCOMObjects(dApplication);
41
            dApplication = null;
42 6a7573b0 gaqhf
            try
43
            {
44
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
45
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
46
            }
47
            catch (Exception ex)
48
            {
49
                StringBuilder sb = new StringBuilder();
50
                sb.AppendLine(ex.Message);
51
                sb.AppendLine(ex.StackTrace);
52
                MessageBox.Show(sb.ToString());
53
            }
54
55 1ba9c671 gaqhf
#if DEBUG
56
            simpleButton1.Visible = true;
57 51ae61b9 gaqhf
58 4fb0f8d5 gaqhf
            
59 1ba9c671 gaqhf
#endif
60 65881d60 gaqhf
        }
61
62 e3e2d41f gaqhf
        private void btnConverter_Click(object sender, EventArgs e)
63 65881d60 gaqhf
        {
64 1ba9c671 gaqhf
            ConverterForm converterForm = new ConverterForm();
65
            if (converterForm.ShowDialog() == DialogResult.OK)
66 65881d60 gaqhf
            {
67 4941f5fe gaqhf
                //Ingr.RAD2D.Document doc = application.Documents.Add();
68
69 1ba9c671 gaqhf
                try
70
                {
71
                    CloseOPCForm.Run();
72 ca214bc3 gaqhf
73 d5ec4d0f gaqhf
                    for (int i = 0; i < converterForm.Documents.Count; i++)
74 1ba9c671 gaqhf
                    {
75 d5ec4d0f gaqhf
                        SPPID_Document document = converterForm.Documents[i];
76 1ba9c671 gaqhf
                        if (document.SetSPPIDMapping() && document.Enable)
77
                        {
78 4941f5fe gaqhf
                            AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked);
79 d5ec4d0f gaqhf
                            modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
80 1ba9c671 gaqhf
                            modeling.Run();
81
                        }
82
                    }
83
                }
84
                catch (Exception ex)
85
                {
86
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
87
                }
88
                finally
89 d19ae675 gaqhf
                {
90 1ba9c671 gaqhf
                    CloseOPCForm.Stop();
91 4941f5fe gaqhf
92
                    //doc.SaveOnClose = false;
93
                    //doc.Close(false);
94
95
                    //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
96
                    //dApplication.Drawings[1].CloseDrawing(false);
97
                    //ReleaseCOMObjects(dApplication);
98
                    //dApplication = null;
99 1ba9c671 gaqhf
                }
100
101
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
102
            }
103
        }
104
105 69b7387a gaqhf
        private void btnLinkOPC_Click(object sender, EventArgs e)
106
        {
107 4941f5fe gaqhf
            if (application.ActiveDocument == null)
108
                application.Documents.Add();
109 69b7387a gaqhf
110 4941f5fe gaqhf
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
111
            //WrapperApplication wApp = new WrapperApplication(application.Application);
112
            //Ingr.RAD2D.Application radApp = wApp.RADApplication;
113 e8536f2b gaqhf
114 4941f5fe gaqhf
            //LMADataSource dataSource = new LMADataSource();
115
            //LMDrawings drawings = new LMDrawings();
116 69b7387a gaqhf
117 4941f5fe gaqhf
            ////try
118
            //{
119
            //    Project_Info _ProjectInfo = Project_Info.GetInstance();
120
            //    _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
121
            //    if (Project_DB.ConnTestAndCreateTable())
122
            //    {
123
            //        DataTable dt = Project_DB.SelectSPPID_DB_INFO();
124
            //        if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
125
            //            SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
126
            //        else
127
            //            SPPID_DBInfo.Clear();
128
129
            //        SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance();
130
            //        if (sPPID_DBInfo.Enable)
131
            //        {
132
            //            drawings.Collect(dataSource);
133
134
            //            DataTable drawingTable = Project_DB.SelectDrawingInfo();
135
            //            drawingTable.Columns.Add("EXIST", typeof(bool));
136
            //            drawingTable.Columns.Add("SPPIDPATH", typeof(string));
137
138
            //            foreach (LMDrawing item in drawings)
139
            //            {
140
            //                DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value()));
141
            //                foreach (DataRow row in rows)
142
            //                {
143
            //                    row["EXIST"] = true;
144
            //                    row["DRAWINGNAME"] = item.Attributes["Name"].get_Value();
145
            //                    row["SPPIDPATH"] = item.get_Path();
146
            //                }
147
            //            }
148
149
            //            List<SPPID_Document> allDocuments = new List<SPPID_Document>();
150
            //            foreach (DataRow row in drawingTable.Rows)
151
            //                allDocuments.Add((SPPID_Document)row["DOCUMENT"]);
152
153
            //            AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp);
154
            //            opc.Run();
155
            //        }
156
            //    }
157
            //    else
158
            //    {
159
            //        MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
160
            //    }
161
            //}
162
            ////catch (Exception ex)
163
            //{
164
            //    //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
165
            //}
166
            ////finally
167
            //{
168
            //    ReleaseCOMObjects(dataSource);
169
            //    ReleaseCOMObjects(drawings);
170
            //}
171 69b7387a gaqhf
        }
172
173 4fb0f8d5 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
174
        {
175
            int intNewRefCount = 0;
176
            foreach (object obj in objVars)
177
            {
178
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
179
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
180
            }
181
        }
182
183 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
184 1ba9c671 gaqhf
        {
185 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
186
            WrapperApplication wApp = new WrapperApplication(application.Application);
187
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
188
189 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
190 65881d60 gaqhf
            {
191 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
192
                if (line2D != null)
193 1ba9c671 gaqhf
                {
194 6a7573b0 gaqhf
                    double minX = 0;
195
                    double minY = 0;
196
                    double maxX = 0;
197
                    double maxY = 0;
198
                    line2D.Range(out minX, out minY, out maxX, out maxY);
199
200
                    Settings.Default.DrawingX = maxX - minX;
201
                    Settings.Default.DrawingY = maxY - minY;
202
                    Settings.Default.Save();
203
204
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
205
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
206 1ba9c671 gaqhf
                }
207 6a7573b0 gaqhf
                else
208
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
209 65881d60 gaqhf
            }
210 6a7573b0 gaqhf
            else
211
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
212
        }
213 7e4a64a3 gaqhf
214
        #region TEST
215 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
216
        {
217 4941f5fe gaqhf
            Thread outThread = new Thread(func2 =>
218
            {
219
                for (int i = 100; i < 120; i++)
220
                {
221
                    Thread thread = new Thread(func =>
222
                    {
223
                        dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
224
                        //WrapperApplication wApp = new WrapperApplication(application.Application);
225
                        //Ingr.RAD2D.Application radApp = wApp.RADApplication;
226
                        dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123");
227
228
                        Thread.Sleep(5000);
229
230
                        drawing.CloseDrawing(true);
231
232
                        //application.Quit();
233
                        ReleaseCOMObjects(application);
234
                        application = null;
235
                        ReleaseCOMObjects(drawing);
236
                        drawing = null;
237
                        Thread.Sleep(5000);
238
                    });
239
                    thread.Start();
240
                    thread.Join();
241
                }
242
            });
243
            outThread.Start();
244
            
245
            
246
247 32205389 gaqhf
248 ca6e0f51 gaqhf
249 4941f5fe gaqhf
            //radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid");
250
251
            //radApp.ActiveDocument.Close(true);
252
            //drawing.CloseDrawing(true);
253
254
            //ReleaseCOMObjects(application);
255
            //ReleaseCOMObjects(drawing);
256
            //application = null;
257
            //wApp = null;
258
            //radApp = null;
259
            //drawing = null;
260 ca6e0f51 gaqhf
        }
261 4941f5fe gaqhf
262 ca6e0f51 gaqhf
        private void AutoJoinPipeRun()
263
        {
264 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
265
            WrapperApplication wApp = new WrapperApplication(application.Application);
266
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
267
268 ca6e0f51 gaqhf
            string modelItemId = null;
269
            List<double[]> vertices = new List<double[]>();
270 a31a512e gaqhf
            if (radApp.ActiveSelectSet.Count == 0)
271
            {
272
                return;
273
            }
274 ca6e0f51 gaqhf
            dynamic OID = radApp.ActiveSelectSet[0].Key();
275
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
276
            foreach (var attributes in drawingObject.AttributeSets)
277 4ba01591 gaqhf
            {
278 ca6e0f51 gaqhf
                foreach (var attribute in attributes)
279 4ba01591 gaqhf
                {
280 ca6e0f51 gaqhf
                    if (attribute.Name == "ModelID")
281
                        modelItemId = attribute.GetValue().ToString();
282
                }
283
            }
284
            radApp.ActiveSelectSet.RemoveAll();
285 32205389 gaqhf
286 7e4a64a3 gaqhf
        }
287
        #endregion
288
289 7aee331b gaqhf
290 9628f54b gaqhf
        [DllImport("user32.dll")]
291
        public static extern int FindWindow(string lpClassName, string lpWindowName);
292 3734dcc5 gaqhf
293
        [DllImport("user32.dll", SetLastError = true)]
294
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
295
296 65881d60 gaqhf
    }
297
}
클립보드 이미지 추가 (최대 크기: 500 MB)