프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (11.2 KB)

1
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
using System.IO;
12
using Microsoft.VisualBasic;
13
using Ingr.RAD2D;
14
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
using Plaice;
21
using Llama;
22
using DevExpress.XtraSplashScreen;
23
using Newtonsoft.Json;
24
using System.Runtime.InteropServices;
25
using System.Reflection;
26

    
27
namespace Converter.SPPID.Wrapper
28
{
29
    public partial class ConverterDocking : UserControl
30
    {
31
        Ingr.RAD2D.Application application;
32
        public ConverterDocking()
33
        {
34
            InitializeComponent();
35

    
36
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
37
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
38
            application = wApp.RADApplication;
39
            
40
            ReleaseCOMObjects(dApplication);
41
            dApplication = null;
42
            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
#if DEBUG
56
            simpleButton1.Visible = true;
57

    
58
            
59
#endif
60
        }
61

    
62
        private void btnConverter_Click(object sender, EventArgs e)
63
        {
64
            ConverterForm converterForm = new ConverterForm();
65
            if (converterForm.ShowDialog() == DialogResult.OK)
66
            {
67
                //Ingr.RAD2D.Document doc = application.Documents.Add();
68

    
69
                try
70
                {
71
                    CloseOPCForm.Run();
72

    
73
                    for (int i = 0; i < converterForm.Documents.Count; i++)
74
                    {
75
                        SPPID_Document document = converterForm.Documents[i];
76
                        if (document.SetSPPIDMapping() && document.Enable)
77
                        {
78
                            AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked);
79
                            modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
80
                            modeling.Run();
81
                        }
82
                    }
83
                }
84
                catch (Exception ex)
85
                {
86
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
87
                }
88
                finally
89
                {
90
                    CloseOPCForm.Stop();
91

    
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
                }
100

    
101
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
102
            }
103
        }
104

    
105
        private void btnLinkOPC_Click(object sender, EventArgs e)
106
        {
107
            if (application.ActiveDocument == null)
108
                application.Documents.Add();
109

    
110
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
111
            //WrapperApplication wApp = new WrapperApplication(application.Application);
112
            //Ingr.RAD2D.Application radApp = wApp.RADApplication;
113

    
114
            //LMADataSource dataSource = new LMADataSource();
115
            //LMDrawings drawings = new LMDrawings();
116

    
117
            ////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
        }
172

    
173
        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
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
184
        {
185
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
186
            WrapperApplication wApp = new WrapperApplication(application.Application);
187
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
188

    
189
            if (radApp.ActiveSelectSet.Count > 0)
190
            {
191
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
192
                if (line2D != null)
193
                {
194
                    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
                }
207
                else
208
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
209
            }
210
            else
211
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
212
        }
213

    
214
        #region TEST
215
        private void simpleButton1_Click(object sender, EventArgs e)
216
        {
217
            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

    
248

    
249
            //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
        }
261

    
262
        private void AutoJoinPipeRun()
263
        {
264
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
265
            WrapperApplication wApp = new WrapperApplication(application.Application);
266
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
267

    
268
            string modelItemId = null;
269
            List<double[]> vertices = new List<double[]>();
270
            if (radApp.ActiveSelectSet.Count == 0)
271
            {
272
                return;
273
            }
274
            dynamic OID = radApp.ActiveSelectSet[0].Key();
275
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
276
            foreach (var attributes in drawingObject.AttributeSets)
277
            {
278
                foreach (var attribute in attributes)
279
                {
280
                    if (attribute.Name == "ModelID")
281
                        modelItemId = attribute.GetValue().ToString();
282
                }
283
            }
284
            radApp.ActiveSelectSet.RemoveAll();
285

    
286
        }
287
        #endregion
288

    
289

    
290
        [DllImport("user32.dll")]
291
        public static extern int FindWindow(string lpClassName, string lpWindowName);
292

    
293
        [DllImport("user32.dll", SetLastError = true)]
294
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
295

    
296
    }
297
}
클립보드 이미지 추가 (최대 크기: 500 MB)