hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ bccacd6c
이력 | 보기 | 이력해설 | 다운로드 (11.7 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 |
|
56 |
/// <summary> |
57 |
/// 선택한 도면들을 읽어서 SPPID로 변환한다. |
58 |
/// </summary> |
59 |
/// <param name="sender"></param> |
60 |
/// <param name="e"></param> |
61 |
private void btnConverter_Click(object sender, EventArgs e) |
62 |
{ |
63 |
ConverterForm converterForm = new ConverterForm(); |
64 |
if (converterForm.ShowDialog() == DialogResult.OK) |
65 |
{ |
66 |
//Ingr.RAD2D.Document doc = application.Documents.Add(); |
67 |
|
68 |
try |
69 |
{ |
70 |
CloseOPCForm.Run(); |
71 |
|
72 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
73 |
{ |
74 |
SPPID_Document document = converterForm.Documents[i]; |
75 |
if (document.SetSPPIDMapping() && document.Enable) |
76 |
{ |
77 |
using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked)) |
78 |
{ |
79 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
80 |
modeling.Run(); |
81 |
} |
82 |
} |
83 |
} |
84 |
} |
85 |
catch (Exception ex) |
86 |
{ |
87 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
88 |
} |
89 |
finally |
90 |
{ |
91 |
CloseOPCForm.Stop(); |
92 |
|
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 |
} |
101 |
|
102 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
103 |
} |
104 |
} |
105 |
|
106 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
107 |
{ |
108 |
if (application.ActiveDocument == null) |
109 |
application.Documents.Add(); |
110 |
|
111 |
//dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
112 |
//WrapperApplication wApp = new WrapperApplication(application.Application); |
113 |
//Ingr.RAD2D.Application radApp = wApp.RADApplication; |
114 |
|
115 |
//LMADataSource dataSource = new LMADataSource(); |
116 |
//LMDrawings drawings = new LMDrawings(); |
117 |
|
118 |
////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 |
} |
173 |
|
174 |
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 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
185 |
{ |
186 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
187 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
188 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
189 |
|
190 |
if (radApp.ActiveSelectSet.Count > 0) |
191 |
{ |
192 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
193 |
if (line2D != null) |
194 |
{ |
195 |
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 |
} |
208 |
else |
209 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
210 |
} |
211 |
else |
212 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
213 |
} |
214 |
|
215 |
#region TEST |
216 |
private void simpleButton1_Click(object sender, EventArgs e) |
217 |
{ |
218 |
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 |
|
249 |
|
250 |
//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 |
} |
262 |
|
263 |
private void AutoJoinPipeRun() |
264 |
{ |
265 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
266 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
267 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
268 |
|
269 |
string modelItemId = null; |
270 |
List<double[]> vertices = new List<double[]>(); |
271 |
if (radApp.ActiveSelectSet.Count == 0) |
272 |
{ |
273 |
return; |
274 |
} |
275 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
276 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
277 |
foreach (var attributes in drawingObject.AttributeSets) |
278 |
{ |
279 |
foreach (var attribute in attributes) |
280 |
{ |
281 |
if (attribute.Name == "ModelID") |
282 |
modelItemId = attribute.GetValue().ToString(); |
283 |
} |
284 |
} |
285 |
radApp.ActiveSelectSet.RemoveAll(); |
286 |
|
287 |
} |
288 |
#endregion |
289 |
|
290 |
|
291 |
[DllImport("user32.dll")] |
292 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
293 |
|
294 |
[DllImport("user32.dll", SetLastError = true)] |
295 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
296 |
|
297 |
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 |
} |
307 |
} |