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
|
using Converter.SPPID.OPC;
|
27
|
|
28
|
namespace Converter.SPPID.Wrapper
|
29
|
{
|
30
|
public partial class ConverterDocking : UserControl
|
31
|
{
|
32
|
Ingr.RAD2D.Application application;
|
33
|
public ConverterDocking()
|
34
|
{
|
35
|
InitializeComponent();
|
36
|
|
37
|
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
|
38
|
WrapperApplication wApp = new WrapperApplication(dApplication.Application);
|
39
|
application = wApp.RADApplication;
|
40
|
|
41
|
ReleaseCOMObjects(dApplication);
|
42
|
dApplication = null;
|
43
|
try
|
44
|
{
|
45
|
textEditDrawingX.EditValue = Settings.Default.DrawingX;
|
46
|
textEditDrawingY.EditValue = Settings.Default.DrawingY;
|
47
|
|
48
|
Project_Info _ProjectInfo = Project_Info.GetInstance();
|
49
|
_ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
|
50
|
_ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
|
51
|
_ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
|
52
|
_ProjectInfo.Port = Settings.Default.ProjectPort;
|
53
|
_ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
|
54
|
_ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
|
55
|
}
|
56
|
catch (Exception ex)
|
57
|
{
|
58
|
StringBuilder sb = new StringBuilder();
|
59
|
sb.AppendLine(ex.Message);
|
60
|
sb.AppendLine(ex.StackTrace);
|
61
|
MessageBox.Show(sb.ToString());
|
62
|
}
|
63
|
}
|
64
|
|
65
|
/// <summary>
|
66
|
/// 선택한 도면들을 읽어서 SPPID로 변환한다.
|
67
|
/// </summary>
|
68
|
/// <param name="sender"></param>
|
69
|
/// <param name="e"></param>
|
70
|
private void btnConverter_Click(object sender, EventArgs e)
|
71
|
{
|
72
|
ConverterForm converterForm = new ConverterForm();
|
73
|
if (converterForm.ShowDialog() == DialogResult.OK)
|
74
|
{
|
75
|
//Ingr.RAD2D.Document doc = application.Documents.Add();
|
76
|
|
77
|
try
|
78
|
{
|
79
|
CloseOPCForm.Run();
|
80
|
|
81
|
for (int i = 0; i < converterForm.Documents.Count; i++)
|
82
|
{
|
83
|
SPPID_Document document = converterForm.Documents[i];
|
84
|
if (document.SetSPPIDMapping() && document.Enable)
|
85
|
{
|
86
|
using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked))
|
87
|
{
|
88
|
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
|
89
|
modeling.Run();
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
catch (Exception ex)
|
95
|
{
|
96
|
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
|
97
|
}
|
98
|
finally
|
99
|
{
|
100
|
CloseOPCForm.Stop();
|
101
|
|
102
|
//doc.SaveOnClose = false;
|
103
|
//doc.Close(false);
|
104
|
|
105
|
//dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
|
106
|
//dApplication.Drawings[1].CloseDrawing(false);
|
107
|
//ReleaseCOMObjects(dApplication);
|
108
|
//dApplication = null;
|
109
|
}
|
110
|
|
111
|
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
112
|
}
|
113
|
}
|
114
|
|
115
|
private void btnLinkOPC_Click(object sender, EventArgs e)
|
116
|
{
|
117
|
DataTable tOPCInfo = Project_DB.SelectOPCInfo();
|
118
|
DataTable tOPCRelations = Project_DB.SelectOPCRelations();
|
119
|
DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
|
120
|
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
|
121
|
|
122
|
foreach (DataRow row in tOPCInfo.Rows)
|
123
|
{
|
124
|
if (!Convert.ToBoolean(row["PAIRED"]))
|
125
|
{
|
126
|
string drawingUID = row["ID2_DRAWING_UID"].ToString();
|
127
|
string OPCUID = row["ID2_OPC_UID"].ToString();
|
128
|
DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID));
|
129
|
|
130
|
if (rows.Length == 2)
|
131
|
{
|
132
|
string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
|
133
|
string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
|
134
|
string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
|
135
|
string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
|
136
|
string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
|
137
|
string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
|
138
|
string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
|
139
|
string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
|
140
|
|
141
|
DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
|
142
|
DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
|
143
|
DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
|
144
|
DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
|
145
|
|
146
|
if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
|
147
|
{
|
148
|
DataRow fromOPCInfoRow = fromOPCInfoRows[0];
|
149
|
DataRow toOPCInfoRow = toOPCInfoRows[0];
|
150
|
string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
|
151
|
string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
|
152
|
string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
|
153
|
List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
|
154
|
AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
|
155
|
if (opc.Run())
|
156
|
{
|
157
|
fromOPCInfoRow["PAIRED"] = true;
|
158
|
toOPCInfoRow["PAIRED"] = true;
|
159
|
|
160
|
Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
|
161
|
Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
|
168
|
tOPCInfo.Dispose();
|
169
|
tOPCRelations.Dispose();
|
170
|
tDrawingInfo.Dispose();
|
171
|
ReleaseCOMObjects(dApplication);
|
172
|
dApplication = null;
|
173
|
|
174
|
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
175
|
}
|
176
|
|
177
|
public void ReleaseCOMObjects(params object[] objVars)
|
178
|
{
|
179
|
int intNewRefCount = 0;
|
180
|
foreach (object obj in objVars)
|
181
|
{
|
182
|
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
|
183
|
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
|
184
|
}
|
185
|
}
|
186
|
|
187
|
private void btnGetDrawingSize_Click(object sender, EventArgs e)
|
188
|
{
|
189
|
dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
|
190
|
WrapperApplication wApp = new WrapperApplication(application.Application);
|
191
|
Ingr.RAD2D.Application radApp = wApp.RADApplication;
|
192
|
|
193
|
if (radApp.ActiveSelectSet.Count > 0)
|
194
|
{
|
195
|
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
|
196
|
if (line2D != null)
|
197
|
{
|
198
|
double minX = 0;
|
199
|
double minY = 0;
|
200
|
double maxX = 0;
|
201
|
double maxY = 0;
|
202
|
line2D.Range(out minX, out minY, out maxX, out maxY);
|
203
|
|
204
|
Settings.Default.DrawingX = maxX - minX;
|
205
|
Settings.Default.DrawingY = maxY - minY;
|
206
|
Settings.Default.Save();
|
207
|
|
208
|
textEditDrawingX.EditValue = Settings.Default.DrawingX;
|
209
|
textEditDrawingY.EditValue = Settings.Default.DrawingY;
|
210
|
}
|
211
|
else
|
212
|
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
213
|
}
|
214
|
else
|
215
|
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
216
|
}
|
217
|
|
218
|
#region TEST
|
219
|
private void simpleButton1_Click(object sender, EventArgs e)
|
220
|
{
|
221
|
foreach (RADObject item in application.ActiveDocument.SelectSet)
|
222
|
{
|
223
|
DependencyObject dependencyObject = item as DependencyObject;
|
224
|
if (dependencyObject != null)
|
225
|
{
|
226
|
double minX = 0;
|
227
|
double minY = 0;
|
228
|
double maxX = 0;
|
229
|
double maxY = 0;
|
230
|
dependencyObject.DrawingObjects[0].Range(out minX, out minY, out maxX, out maxY);
|
231
|
}
|
232
|
Symbol2d symbol2D = item as Symbol2d;
|
233
|
if (symbol2D != null)
|
234
|
{
|
235
|
double minX = 0;
|
236
|
double minY = 0;
|
237
|
double maxX = 0;
|
238
|
double maxY = 0;
|
239
|
symbol2D.Range(out minX, out minY, out maxX, out maxY);
|
240
|
}
|
241
|
}
|
242
|
|
243
|
|
244
|
|
245
|
return;
|
246
|
Thread outThread = new Thread(func2 =>
|
247
|
{
|
248
|
for (int i = 100; i < 120; i++)
|
249
|
{
|
250
|
Thread thread = new Thread(func =>
|
251
|
{
|
252
|
dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
|
253
|
//WrapperApplication wApp = new WrapperApplication(application.Application);
|
254
|
//Ingr.RAD2D.Application radApp = wApp.RADApplication;
|
255
|
dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123");
|
256
|
|
257
|
Thread.Sleep(5000);
|
258
|
|
259
|
drawing.CloseDrawing(true);
|
260
|
|
261
|
//application.Quit();
|
262
|
ReleaseCOMObjects(application);
|
263
|
application = null;
|
264
|
ReleaseCOMObjects(drawing);
|
265
|
drawing = null;
|
266
|
Thread.Sleep(5000);
|
267
|
});
|
268
|
thread.Start();
|
269
|
thread.Join();
|
270
|
}
|
271
|
});
|
272
|
outThread.Start();
|
273
|
|
274
|
|
275
|
|
276
|
|
277
|
|
278
|
//radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid");
|
279
|
|
280
|
//radApp.ActiveDocument.Close(true);
|
281
|
//drawing.CloseDrawing(true);
|
282
|
|
283
|
//ReleaseCOMObjects(application);
|
284
|
//ReleaseCOMObjects(drawing);
|
285
|
//application = null;
|
286
|
//wApp = null;
|
287
|
//radApp = null;
|
288
|
//drawing = null;
|
289
|
}
|
290
|
|
291
|
private void AutoJoinPipeRun()
|
292
|
{
|
293
|
dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
|
294
|
WrapperApplication wApp = new WrapperApplication(application.Application);
|
295
|
Ingr.RAD2D.Application radApp = wApp.RADApplication;
|
296
|
|
297
|
string modelItemId = null;
|
298
|
List<double[]> vertices = new List<double[]>();
|
299
|
if (radApp.ActiveSelectSet.Count == 0)
|
300
|
{
|
301
|
return;
|
302
|
}
|
303
|
dynamic OID = radApp.ActiveSelectSet[0].Key();
|
304
|
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
|
305
|
foreach (var attributes in drawingObject.AttributeSets)
|
306
|
{
|
307
|
foreach (var attribute in attributes)
|
308
|
{
|
309
|
if (attribute.Name == "ModelID")
|
310
|
modelItemId = attribute.GetValue().ToString();
|
311
|
}
|
312
|
}
|
313
|
radApp.ActiveSelectSet.RemoveAll();
|
314
|
|
315
|
}
|
316
|
#endregion
|
317
|
|
318
|
|
319
|
[DllImport("user32.dll")]
|
320
|
public static extern int FindWindow(string lpClassName, string lpWindowName);
|
321
|
|
322
|
[DllImport("user32.dll", SetLastError = true)]
|
323
|
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
|
324
|
|
325
|
private void ConverterDocking_Load(object sender, EventArgs e)
|
326
|
{
|
327
|
#if DEBUG
|
328
|
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
|
329
|
#else
|
330
|
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
331
|
#endif
|
332
|
|
333
|
}
|
334
|
}
|
335
|
}
|