hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 9628f54b
이력 | 보기 | 이력해설 | 다운로드 (7.79 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 | 65881d60 | gaqhf | |
26 | namespace Converter.SPPID.Wrapper |
||
27 | { |
||
28 | public partial class ConverterDocking : UserControl |
||
29 | { |
||
30 | e3e2d41f | gaqhf | Ingr.RAD2D.Application radApp; |
31 | d19ae675 | gaqhf | dynamic application; |
32 | 65881d60 | gaqhf | public ConverterDocking() |
33 | { |
||
34 | InitializeComponent(); |
||
35 | d19ae675 | gaqhf | application = Interaction.GetObject("", "PIDAutomation.Application"); |
36 | e3e2d41f | gaqhf | WrapperApplication wApp = new WrapperApplication(application.Application); |
37 | radApp = wApp.RADApplication; |
||
38 | 1ba9c671 | gaqhf | |
39 | 6a7573b0 | gaqhf | try |
40 | { |
||
41 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
42 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
43 | } |
||
44 | catch (Exception ex) |
||
45 | { |
||
46 | StringBuilder sb = new StringBuilder(); |
||
47 | sb.AppendLine(ex.Message); |
||
48 | sb.AppendLine(ex.StackTrace); |
||
49 | MessageBox.Show(sb.ToString()); |
||
50 | } |
||
51 | |||
52 | |||
53 | 1ba9c671 | gaqhf | #if DEBUG |
54 | simpleButton1.Visible = true; |
||
55 | 51ae61b9 | gaqhf | |
56 | 4fb0f8d5 | gaqhf | |
57 | 1ba9c671 | gaqhf | #endif |
58 | 65881d60 | gaqhf | } |
59 | |||
60 | e3e2d41f | gaqhf | private void btnConverter_Click(object sender, EventArgs e) |
61 | 65881d60 | gaqhf | { |
62 | 1ba9c671 | gaqhf | ConverterForm converterForm = new ConverterForm(); |
63 | if (converterForm.ShowDialog() == DialogResult.OK) |
||
64 | 65881d60 | gaqhf | { |
65 | 1ba9c671 | gaqhf | try |
66 | { |
||
67 | CloseOPCForm.Run(); |
||
68 | ca214bc3 | gaqhf | |
69 | d5ec4d0f | gaqhf | for (int i = 0; i < converterForm.Documents.Count; i++) |
70 | 1ba9c671 | gaqhf | { |
71 | d5ec4d0f | gaqhf | SPPID_Document document = converterForm.Documents[i]; |
72 | 1ba9c671 | gaqhf | if (document.SetSPPIDMapping() && document.Enable) |
73 | { |
||
74 | AutoModeling modeling = new AutoModeling(document, application, radApp); |
||
75 | d5ec4d0f | gaqhf | modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
76 | 1ba9c671 | gaqhf | modeling.Run(); |
77 | } |
||
78 | } |
||
79 | } |
||
80 | catch (Exception ex) |
||
81 | { |
||
82 | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
83 | } |
||
84 | finally |
||
85 | d19ae675 | gaqhf | { |
86 | 1ba9c671 | gaqhf | CloseOPCForm.Stop(); |
87 | } |
||
88 | |||
89 | MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | 69b7387a | gaqhf | private void btnLinkOPC_Click(object sender, EventArgs e) |
94 | { |
||
95 | 4fb0f8d5 | gaqhf | LMADataSource dataSource = new LMADataSource(); |
96 | LMDrawings drawings = new LMDrawings(); |
||
97 | |||
98 | 69b7387a | gaqhf | try |
99 | { |
||
100 | 4fb0f8d5 | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
101 | _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
||
102 | if (Project_DB.ConnTestAndCreateTable()) |
||
103 | { |
||
104 | 224535bb | gaqhf | DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
105 | if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
||
106 | SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
||
107 | else |
||
108 | SPPID_DBInfo.Clear(); |
||
109 | |||
110 | SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance(); |
||
111 | if (sPPID_DBInfo.Enable) |
||
112 | { |
||
113 | drawings.Collect(dataSource); |
||
114 | 69b7387a | gaqhf | |
115 | 224535bb | gaqhf | DataTable drawingTable = Project_DB.SelectDrawingInfo(); |
116 | drawingTable.Columns.Add("EXIST", typeof(bool)); |
||
117 | drawingTable.Columns.Add("SPPIDPATH", typeof(string)); |
||
118 | e8536f2b | gaqhf | |
119 | 224535bb | gaqhf | foreach (LMDrawing item in drawings) |
120 | { |
||
121 | DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value())); |
||
122 | foreach (DataRow row in rows) |
||
123 | { |
||
124 | row["EXIST"] = true; |
||
125 | row["DRAWINGNAME"] = item.Attributes["Name"].get_Value(); |
||
126 | row["SPPIDPATH"] = item.get_Path(); |
||
127 | } |
||
128 | } |
||
129 | 69b7387a | gaqhf | |
130 | 1ed39474 | gaqhf | List<SPPID_Document> allDocuments = new List<SPPID_Document>(); |
131 | 224535bb | gaqhf | foreach (DataRow row in drawingTable.Rows) |
132 | { |
||
133 | SPPID_Document document = JsonConvert.DeserializeObject<SPPID_Document>(row["DOCUMENT"].ToString()); |
||
134 | 1ed39474 | gaqhf | allDocuments.Add(document); |
135 | 224535bb | gaqhf | } |
136 | 1ed39474 | gaqhf | |
137 | 71ba1ca3 | gaqhf | AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp, drawingTable); |
138 | 1ed39474 | gaqhf | opc.Run(); |
139 | 224535bb | gaqhf | //dynamic doc = application.Drawings.OpenDrawing(drawingTable.Rows[0]["DRAWINGNAME"]); |
140 | e8536f2b | gaqhf | |
141 | 224535bb | gaqhf | //doc.CloseDrawing(true); |
142 | |||
143 | |||
144 | |||
145 | //radApp.Documents.Open(sPPID_DBInfo.PlantPath + @"\" + drawingTable.Rows[0]["SPPIDPATH"].ToString()); |
||
146 | } |
||
147 | 4fb0f8d5 | gaqhf | } |
148 | else |
||
149 | { |
||
150 | MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
151 | } |
||
152 | 69b7387a | gaqhf | } |
153 | catch (Exception ex) |
||
154 | { |
||
155 | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
156 | } |
||
157 | 4fb0f8d5 | gaqhf | finally |
158 | { |
||
159 | ReleaseCOMObjects(dataSource); |
||
160 | ReleaseCOMObjects(drawings); |
||
161 | } |
||
162 | 69b7387a | gaqhf | } |
163 | |||
164 | 4fb0f8d5 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
165 | { |
||
166 | int intNewRefCount = 0; |
||
167 | foreach (object obj in objVars) |
||
168 | { |
||
169 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
170 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
171 | } |
||
172 | } |
||
173 | |||
174 | |||
175 | 6a7573b0 | gaqhf | private void btnGetDrawingSize_Click(object sender, EventArgs e) |
176 | 1ba9c671 | gaqhf | { |
177 | 6a7573b0 | gaqhf | if (radApp.ActiveSelectSet.Count > 0) |
178 | 65881d60 | gaqhf | { |
179 | 6a7573b0 | gaqhf | DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
180 | if (line2D != null) |
||
181 | 1ba9c671 | gaqhf | { |
182 | 6a7573b0 | gaqhf | double minX = 0; |
183 | double minY = 0; |
||
184 | double maxX = 0; |
||
185 | double maxY = 0; |
||
186 | line2D.Range(out minX, out minY, out maxX, out maxY); |
||
187 | |||
188 | Settings.Default.DrawingX = maxX - minX; |
||
189 | Settings.Default.DrawingY = maxY - minY; |
||
190 | Settings.Default.Save(); |
||
191 | |||
192 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
193 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
194 | 1ba9c671 | gaqhf | } |
195 | 6a7573b0 | gaqhf | else |
196 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
197 | 65881d60 | gaqhf | } |
198 | 6a7573b0 | gaqhf | else |
199 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
200 | } |
||
201 | |||
202 | private void simpleButton1_Click(object sender, EventArgs e) |
||
203 | { |
||
204 | 1ab9a205 | gaqhf | Placement _placement = new Placement(); |
205 | 6a7573b0 | gaqhf | LMADataSource dataSource = new LMADataSource();//placement.PIDDataSource; |
206 | |||
207 | 9628f54b | gaqhf | |
208 | 224535bb | gaqhf | |
209 | 65881d60 | gaqhf | } |
210 | 9628f54b | gaqhf | [DllImport("user32.dll")] |
211 | public static extern int FindWindow(string lpClassName, string lpWindowName); |
||
212 | 6a7573b0 | gaqhf | |
213 | 65881d60 | gaqhf | } |
214 | } |