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