hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ b427ebf9
이력 | 보기 | 이력해설 | 다운로드 (17.4 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 |
|
26 |
namespace Converter.SPPID.Wrapper |
27 |
{ |
28 |
public partial class ConverterDocking : UserControl |
29 |
{ |
30 |
|
31 |
public ConverterDocking() |
32 |
{ |
33 |
InitializeComponent(); |
34 |
|
35 |
|
36 |
try |
37 |
{ |
38 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
39 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
40 |
} |
41 |
catch (Exception ex) |
42 |
{ |
43 |
StringBuilder sb = new StringBuilder(); |
44 |
sb.AppendLine(ex.Message); |
45 |
sb.AppendLine(ex.StackTrace); |
46 |
MessageBox.Show(sb.ToString()); |
47 |
} |
48 |
} |
49 |
|
50 |
private void btnConverter_Click(object sender, EventArgs e) |
51 |
{ |
52 |
ConverterForm converterForm = new ConverterForm(); |
53 |
if (converterForm.ShowDialog() == DialogResult.OK) |
54 |
{ |
55 |
try |
56 |
{ |
57 |
CloseOPCForm.Run(); |
58 |
|
59 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
60 |
{ |
61 |
SPPID_Document document = converterForm.Documents[i]; |
62 |
if (document.SetSPPIDMapping() && document.Enable) |
63 |
{ |
64 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
65 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
66 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
67 |
|
68 |
AutoModeling modeling = new AutoModeling(document, application, radApp, converterForm.checkEditCloseDocument.Checked); |
69 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
70 |
modeling.Run(); |
71 |
|
72 |
ReleaseCOMObjects(application); |
73 |
} |
74 |
} |
75 |
} |
76 |
catch (Exception ex) |
77 |
{ |
78 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
79 |
} |
80 |
finally |
81 |
{ |
82 |
CloseOPCForm.Stop(); |
83 |
} |
84 |
|
85 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
86 |
} |
87 |
} |
88 |
|
89 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
90 |
{ |
91 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
92 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
93 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
94 |
|
95 |
LMADataSource dataSource = new LMADataSource(); |
96 |
LMDrawings drawings = new LMDrawings(); |
97 |
|
98 |
//try |
99 |
{ |
100 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
101 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
102 |
if (Project_DB.ConnTestAndCreateTable()) |
103 |
{ |
104 |
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 |
|
115 |
DataTable drawingTable = Project_DB.SelectDrawingInfo(); |
116 |
drawingTable.Columns.Add("EXIST", typeof(bool)); |
117 |
drawingTable.Columns.Add("SPPIDPATH", typeof(string)); |
118 |
|
119 |
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 |
|
130 |
List<SPPID_Document> allDocuments = new List<SPPID_Document>(); |
131 |
foreach (DataRow row in drawingTable.Rows) |
132 |
allDocuments.Add((SPPID_Document)row["DOCUMENT"]); |
133 |
|
134 |
AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp); |
135 |
opc.Run(); |
136 |
} |
137 |
} |
138 |
else |
139 |
{ |
140 |
MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
141 |
} |
142 |
} |
143 |
//catch (Exception ex) |
144 |
{ |
145 |
//MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
146 |
} |
147 |
//finally |
148 |
{ |
149 |
ReleaseCOMObjects(dataSource); |
150 |
ReleaseCOMObjects(drawings); |
151 |
} |
152 |
} |
153 |
|
154 |
public void ReleaseCOMObjects(params object[] objVars) |
155 |
{ |
156 |
int intNewRefCount = 0; |
157 |
foreach (object obj in objVars) |
158 |
{ |
159 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
160 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
161 |
} |
162 |
} |
163 |
|
164 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
165 |
{ |
166 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
167 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
168 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
169 |
|
170 |
if (radApp.ActiveSelectSet.Count > 0) |
171 |
{ |
172 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
173 |
if (line2D != null) |
174 |
{ |
175 |
double minX = 0; |
176 |
double minY = 0; |
177 |
double maxX = 0; |
178 |
double maxY = 0; |
179 |
line2D.Range(out minX, out minY, out maxX, out maxY); |
180 |
|
181 |
Settings.Default.DrawingX = maxX - minX; |
182 |
Settings.Default.DrawingY = maxY - minY; |
183 |
Settings.Default.Save(); |
184 |
|
185 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
186 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
187 |
} |
188 |
else |
189 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
190 |
} |
191 |
else |
192 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
193 |
} |
194 |
|
195 |
#region TEST |
196 |
Placement _placement = new Placement(); |
197 |
LMADataSource dataSource; |
198 |
bool first = true; |
199 |
LMDrawing currentDrawing; |
200 |
private void simpleButton1_Click(object sender, EventArgs e) |
201 |
{ |
202 |
dataSource = _placement.PIDDataSource; |
203 |
|
204 |
string projectNumber = dataSource.ProjectNumber; |
205 |
LMActiveProject activeProject = dataSource.GetActiveProject(); |
206 |
LMAEnumAttLists enumAttLists = dataSource.CodeLists; |
207 |
|
208 |
AutoJoinPipeRun(); |
209 |
} |
210 |
private void AutoJoinPipeRun() |
211 |
{ |
212 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
213 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
214 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
215 |
|
216 |
string modelItemId = null; |
217 |
List<double[]> vertices = new List<double[]>(); |
218 |
if (radApp.ActiveSelectSet.Count == 0) |
219 |
{ |
220 |
return; |
221 |
} |
222 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
223 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
224 |
foreach (var attributes in drawingObject.AttributeSets) |
225 |
{ |
226 |
foreach (var attribute in attributes) |
227 |
{ |
228 |
if (attribute.Name == "ModelID") |
229 |
modelItemId = attribute.GetValue().ToString(); |
230 |
} |
231 |
} |
232 |
radApp.ActiveSelectSet.RemoveAll(); |
233 |
|
234 |
|
235 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
236 |
LMPipeRun run = dataSource.GetPipeRun(modelItem.Id); |
237 |
dynamic dd = run.get_Name(); |
238 |
LMAAttribute att = run.Attributes["FileName"]; |
239 |
//foreach (LMRepresentation rep in modelItem.Representations) |
240 |
//{ |
241 |
// if (!DBNull.Value.Equals(rep.get_FileName())) |
242 |
// { |
243 |
// rep.set_FileName(@"\Instrumentation\Signal Line\Connect to Process.sym"); |
244 |
// } |
245 |
//} |
246 |
|
247 |
|
248 |
} |
249 |
private void JoinRun(string modelId, string mainModelId, ref string survivorId) |
250 |
{ |
251 |
try |
252 |
{ |
253 |
LMModelItem modelItem1 = dataSource.GetModelItem(modelId); |
254 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
255 |
LMModelItem modelItem2 = dataSource.GetModelItem(mainModelId); |
256 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
257 |
|
258 |
// item2가 item1으로 조인 |
259 |
_placement.PIDJoinRuns(ref item1, ref item2); |
260 |
item1.Commit(); |
261 |
item2.Commit(); |
262 |
|
263 |
string beforeID = string.Empty; |
264 |
string afterID = string.Empty; |
265 |
|
266 |
if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active") |
267 |
{ |
268 |
beforeID = modelItem2.Id; |
269 |
afterID = modelItem1.Id; |
270 |
survivorId = afterID; |
271 |
} |
272 |
else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active") |
273 |
{ |
274 |
beforeID = modelItem1.Id; |
275 |
afterID = modelItem2.Id; |
276 |
survivorId = afterID; |
277 |
} |
278 |
else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active") |
279 |
survivorId = null; |
280 |
else |
281 |
{ |
282 |
Log.Write("잘못된 경우"); |
283 |
survivorId = null; |
284 |
} |
285 |
|
286 |
|
287 |
//if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID)) |
288 |
//{ |
289 |
// List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID); |
290 |
// foreach (var line in lines) |
291 |
// line.SPPID.ModelItemId = afterID; |
292 |
//} |
293 |
|
294 |
ReleaseCOMObjects(modelItem1); |
295 |
ReleaseCOMObjects(item1); |
296 |
ReleaseCOMObjects(modelItem2); |
297 |
ReleaseCOMObjects(item2); |
298 |
} |
299 |
catch (Exception ex) |
300 |
{ |
301 |
Log.Write("Join Error"); |
302 |
Log.Write(ex.Message); |
303 |
} |
304 |
} |
305 |
|
306 |
private void JoinRunBySameType(string modelItemId, ref string survivorId) |
307 |
{ |
308 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
309 |
if (modelItem != null) |
310 |
{ |
311 |
foreach (LMRepresentation rep in modelItem.Representations) |
312 |
{ |
313 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
314 |
{ |
315 |
LMConnector connector = dataSource.GetConnector(rep.Id); |
316 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
317 |
{ |
318 |
LMSymbol symbol = connector.ConnectItem1SymbolObject; |
319 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
320 |
if (modelItemIds.Count == 1) |
321 |
{ |
322 |
JoinRun(modelItemIds[0], modelItemId, ref survivorId); |
323 |
if (survivorId != null) |
324 |
break; |
325 |
} |
326 |
} |
327 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
328 |
{ |
329 |
LMSymbol symbol = connector.ConnectItem2SymbolObject; |
330 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
331 |
if (modelItemIds.Count == 1) |
332 |
{ |
333 |
JoinRun(modelItemIds[0], modelItemId, ref survivorId); |
334 |
if (survivorId != null) |
335 |
break; |
336 |
} |
337 |
} |
338 |
} |
339 |
} |
340 |
} |
341 |
} |
342 |
|
343 |
private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId) |
344 |
{ |
345 |
List<string> modelItemIDs = new List<string>(); |
346 |
foreach (LMConnector connector in symbol.Connect1Connectors) |
347 |
{ |
348 |
LMModelItem modelItem = connector.ModelItemObject; |
349 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId) |
350 |
modelItemIDs.Add(modelItem.Id); |
351 |
ReleaseCOMObjects(modelItem); |
352 |
ReleaseCOMObjects(connector); |
353 |
} |
354 |
|
355 |
foreach (LMConnector connector in symbol.Connect2Connectors) |
356 |
{ |
357 |
LMModelItem modelItem = connector.ModelItemObject; |
358 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId) |
359 |
modelItemIDs.Add(modelItem.Id); |
360 |
ReleaseCOMObjects(modelItem); |
361 |
ReleaseCOMObjects(connector); |
362 |
} |
363 |
|
364 |
return modelItemIDs; |
365 |
} |
366 |
|
367 |
private void FindOtherModelItemBySymbolWhereTypePipeRunLoop() |
368 |
{ |
369 |
|
370 |
} |
371 |
|
372 |
private void JoinRunOnlyPipeRun() |
373 |
{ |
374 |
|
375 |
} |
376 |
|
377 |
private void GetConnectPointsCount(LMSymbol symbol,ref int pipeRunCount, ref int signalCount) |
378 |
{ |
379 |
string typeName = symbol.ModelItemObject.get_ItemTypeName().ToString(); |
380 |
if (typeName == "Instrument") |
381 |
{ |
382 |
LMInstrument item = dataSource.GetInstrument(symbol.ModelItemID); |
383 |
pipeRunCount = item.PipingPoints.Count; |
384 |
signalCount = item.SignalPoints.Count; |
385 |
ReleaseCOMObjects(item); |
386 |
} |
387 |
else if (typeName == "PipingComp") |
388 |
{ |
389 |
LMPipingComp item = dataSource.GetPipingComp(symbol.ModelItemID); |
390 |
pipeRunCount = item.PipingPoints.Count; |
391 |
signalCount = item.SignalPoints.Count; |
392 |
ReleaseCOMObjects(item); |
393 |
} |
394 |
} |
395 |
|
396 |
|
397 |
|
398 |
private void TESTLine() |
399 |
{ |
400 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
401 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
402 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
403 |
|
404 |
Placement _placement = new Placement(); |
405 |
LMADataSource dataSource = _placement.PIDDataSource;//placement.PIDDataSource; |
406 |
|
407 |
foreach (var attributes in radApp.ActiveSelectSet[0].AttributeSets) |
408 |
{ |
409 |
foreach (var attribute in attributes) |
410 |
{ |
411 |
if (attribute.Name == "ModelID") |
412 |
{ |
413 |
LMModelItem modelItem = dataSource.GetModelItem(attribute.GetValue().ToString()); |
414 |
foreach (LMRepresentation representation in modelItem.Representations) |
415 |
{ |
416 |
//representa |
417 |
} |
418 |
} |
419 |
} |
420 |
} |
421 |
} |
422 |
#endregion |
423 |
|
424 |
|
425 |
[DllImport("user32.dll")] |
426 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
427 |
|
428 |
[DllImport("user32.dll", SetLastError = true)] |
429 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
430 |
|
431 |
private void ConverterDocking_Load(object sender, EventArgs e) |
432 |
{ |
433 |
#if DEBUG |
434 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
435 |
#else |
436 |
this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
437 |
#endif |
438 |
|
439 |
} |
440 |
} |
441 |
} |