hytos / DTI_PID / SPPIDConverter / AutoModeling_OPC.cs @ 71ba1ca3
이력 | 보기 | 이력해설 | 다운로드 (3.73 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.Data; |
7 |
using Llama; |
8 |
using Plaice; |
9 |
using Ingr.RAD2D.Interop.RAD2D; |
10 |
using Ingr.RAD2D.Internal; |
11 |
using Ingr.RAD2D.Helper; |
12 |
using Converter.BaseModel; |
13 |
using Converter.SPPID.Model; |
14 |
using Converter.SPPID.Properties; |
15 |
using Converter.SPPID.Util; |
16 |
using Converter.SPPID.DB; |
17 |
using Ingr.RAD2D.MacroControls.CmdCtrl; |
18 |
using Ingr.RAD2D; |
19 |
using System.Windows; |
20 |
using System.Threading; |
21 |
using System.Drawing; |
22 |
using Microsoft.VisualBasic; |
23 |
using Newtonsoft.Json; |
24 |
|
25 |
using DevExpress.XtraSplashScreen; |
26 |
namespace Converter.SPPID |
27 |
{ |
28 |
public class AutoModeling_OPC |
29 |
{ |
30 |
Placement _placement; |
31 |
LMADataSource dataSource; |
32 |
dynamic application; |
33 |
Ingr.RAD2D.Application radApp; |
34 |
List<SPPID_Document> allDocuments; |
35 |
DataTable drawingTable; |
36 |
|
37 |
public AutoModeling_OPC(List<SPPID_Document> allDocuments, dynamic application, Ingr.RAD2D.Application radApp, DataTable drawingTable) |
38 |
{ |
39 |
this.application = application; |
40 |
this.radApp = radApp; |
41 |
this.allDocuments = allDocuments; |
42 |
this.drawingTable = drawingTable; |
43 |
} |
44 |
|
45 |
public void Run() |
46 |
{ |
47 |
_placement = new Placement(); |
48 |
dataSource = _placement.PIDDataSource; |
49 |
|
50 |
foreach (var document in allDocuments) |
51 |
{ |
52 |
foreach (var opc in document.SYMBOLS) |
53 |
{ |
54 |
if ((opc.TYPE == "Piping OPC's" || |
55 |
opc.TYPE == "Instrument OPC's") && |
56 |
!string.IsNullOrEmpty(opc.SPPID.ModelItemID)) |
57 |
{ |
58 |
PairedOPCModeling(opc); |
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
ReleaseCOMObjects(_placement); |
64 |
ReleaseCOMObjects(dataSource); |
65 |
} |
66 |
|
67 |
public void PairedOPCModeling(Symbol opc) |
68 |
{ |
69 |
bool result = false; |
70 |
LMOPC _LMOPC = dataSource.GetOPC(opc.SPPID.ModelItemID); |
71 |
LMOPC pairOPC = _LMOPC.pairedWithOPCObject; |
72 |
|
73 |
foreach (LMRepresentation rep in pairOPC.Representations) |
74 |
if (rep.DrawingID != "0") |
75 |
result = true; |
76 |
|
77 |
if (!result) |
78 |
{ |
79 |
// OPC Pair 찾아서 도면 오픈후 Pair 모델링 |
80 |
BaseModel.Attribute pathAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "PATH"); |
81 |
BaseModel.Attribute linkOPCAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "LinkOPC"); |
82 |
|
83 |
DataRow[] rows = drawingTable.Select(string.Format("PATH = '{0}'", pathAttribute.VALUE)); |
84 |
if (rows.Length == 1 && OpenDrawing(rows[0]["DRAWINGNAME"].ToString())) |
85 |
{ |
86 |
|
87 |
} |
88 |
} |
89 |
|
90 |
ReleaseCOMObjects(_LMOPC); |
91 |
ReleaseCOMObjects(pairOPC); |
92 |
} |
93 |
|
94 |
public void ReleaseCOMObjects(params object[] objVars) |
95 |
{ |
96 |
int intNewRefCount = 0; |
97 |
foreach (object obj in objVars) |
98 |
{ |
99 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
100 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
101 |
} |
102 |
} |
103 |
|
104 |
private bool OpenDrawing(string drawingName) |
105 |
{ |
106 |
bool result = false; |
107 |
try |
108 |
{ |
109 |
|
110 |
|
111 |
//dynamic doc = application.Drawings.OpenDrawing(drawingName); |
112 |
//doc.Activate(); |
113 |
|
114 |
result = true; |
115 |
} |
116 |
catch (Exception ex) |
117 |
{ |
118 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
119 |
} |
120 |
|
121 |
return result; |
122 |
} |
123 |
} |
124 |
} |