hytos / DTI_PID / SPPIDConverter / AutoModeling_OPC.cs @ 404185fc
이력 | 보기 | 이력해설 | 다운로드 (5.58 KB)
1 | 69b7387a | gaqhf | 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 | 1ed39474 | gaqhf | List<SPPID_Document> allDocuments; |
35 | 69b7387a | gaqhf | |
36 | 88bac50c | gaqhf | public AutoModeling_OPC(List<SPPID_Document> allDocuments, dynamic application, Ingr.RAD2D.Application radApp) |
37 | 69b7387a | gaqhf | { |
38 | this.application = application; |
||
39 | this.radApp = radApp; |
||
40 | 1ed39474 | gaqhf | this.allDocuments = allDocuments; |
41 | 69b7387a | gaqhf | } |
42 | |||
43 | 224535bb | gaqhf | public void Run() |
44 | 69b7387a | gaqhf | { |
45 | 1ed39474 | gaqhf | _placement = new Placement(); |
46 | dataSource = _placement.PIDDataSource; |
||
47 | 224535bb | gaqhf | |
48 | 1ed39474 | gaqhf | foreach (var document in allDocuments) |
49 | { |
||
50 | foreach (var opc in document.SYMBOLS) |
||
51 | { |
||
52 | if ((opc.TYPE == "Piping OPC's" || |
||
53 | opc.TYPE == "Instrument OPC's") && |
||
54 | !string.IsNullOrEmpty(opc.SPPID.ModelItemID)) |
||
55 | { |
||
56 | PairedOPCModeling(opc); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | 69b7387a | gaqhf | |
61 | 1ed39474 | gaqhf | ReleaseCOMObjects(_placement); |
62 | ReleaseCOMObjects(dataSource); |
||
63 | } |
||
64 | 69b7387a | gaqhf | |
65 | 1ed39474 | gaqhf | public void PairedOPCModeling(Symbol opc) |
66 | { |
||
67 | bool result = false; |
||
68 | LMOPC _LMOPC = dataSource.GetOPC(opc.SPPID.ModelItemID); |
||
69 | LMOPC pairOPC = _LMOPC.pairedWithOPCObject; |
||
70 | 224535bb | gaqhf | |
71 | 1ed39474 | gaqhf | foreach (LMRepresentation rep in pairOPC.Representations) |
72 | if (rep.DrawingID != "0") |
||
73 | result = true; |
||
74 | 224535bb | gaqhf | |
75 | 1ed39474 | gaqhf | if (!result) |
76 | { |
||
77 | // OPC Pair 찾아서 도면 오픈후 Pair 모델링 |
||
78 | 71ba1ca3 | gaqhf | BaseModel.Attribute pathAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "PATH"); |
79 | BaseModel.Attribute linkOPCAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "LinkOPC"); |
||
80 | 224535bb | gaqhf | |
81 | 88bac50c | gaqhf | SPPID_Document targetDocument = allDocuments.Find(x => x.PATH == pathAttribute.VALUE); |
82 | if (targetDocument != null) |
||
83 | 71ba1ca3 | gaqhf | { |
84 | 88bac50c | gaqhf | Symbol targetOPC = SPPIDUtil.FindObjectByUID(targetDocument, linkOPCAttribute.VALUE) as Symbol; |
85 | if (targetOPC != null && OpenDrawing(targetDocument.SPPID_DrawingName)) |
||
86 | { |
||
87 | LMSymbol targetLMOPC = dataSource.GetSymbol(targetOPC.SPPID.RepresentationId); |
||
88 | if (targetLMOPC != null) |
||
89 | { |
||
90 | int mirror = targetLMOPC.get_IsMirroredIndex(); |
||
91 | double angle = Convert.ToDouble(targetLMOPC.get_RotationAngle()); |
||
92 | double x = targetLMOPC.get_XCoordinate(); |
||
93 | double y = targetLMOPC.get_YCoordinate(); |
||
94 | LMSymbol newOPC = null; |
||
95 | foreach (LMConnector LMConnector in targetLMOPC.Avoid1Connectors) |
||
96 | { |
||
97 | _placement.PIDRemovePlacement(targetLMOPC.AsLMRepresentation()); |
||
98 | ReleaseCOMObjects(targetLMOPC); |
||
99 | newOPC = _placement.PIDPlaceSymbol(targetOPC.SPPID.MAPPINGNAME, x, y, Mirror: mirror, Rotation: angle, ExistingItem: pairOPC.AsLMAItem(), TargetItem: LMConnector); |
||
100 | break; |
||
101 | } |
||
102 | |||
103 | if (newOPC == null) |
||
104 | { |
||
105 | foreach (LMConnector LMConnector in targetLMOPC.Avoid2Connectors) |
||
106 | { |
||
107 | _placement.PIDRemovePlacement(targetLMOPC.AsLMRepresentation()); |
||
108 | ReleaseCOMObjects(targetLMOPC); |
||
109 | newOPC = _placement.PIDPlaceSymbol(targetOPC.SPPID.MAPPINGNAME, x, y, Mirror: mirror, Rotation: angle, ExistingItem: pairOPC.AsLMAItem(), TargetItem: LMConnector); |
||
110 | break; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | 71ba1ca3 | gaqhf | } |
116 | } |
||
117 | 224535bb | gaqhf | |
118 | 1ed39474 | gaqhf | ReleaseCOMObjects(_LMOPC); |
119 | ReleaseCOMObjects(pairOPC); |
||
120 | 224535bb | gaqhf | } |
121 | |||
122 | public void ReleaseCOMObjects(params object[] objVars) |
||
123 | { |
||
124 | int intNewRefCount = 0; |
||
125 | foreach (object obj in objVars) |
||
126 | { |
||
127 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
128 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
129 | } |
||
130 | 69b7387a | gaqhf | } |
131 | 1ed39474 | gaqhf | |
132 | 71ba1ca3 | gaqhf | private bool OpenDrawing(string drawingName) |
133 | 1ed39474 | gaqhf | { |
134 | 71ba1ca3 | gaqhf | bool result = false; |
135 | try |
||
136 | { |
||
137 | 88bac50c | gaqhf | dynamic doc = application.Drawings.OpenDrawing(drawingName); |
138 | doc.Activate(); |
||
139 | 71ba1ca3 | gaqhf | |
140 | result = true; |
||
141 | } |
||
142 | catch (Exception ex) |
||
143 | { |
||
144 | System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
145 | } |
||
146 | 1ed39474 | gaqhf | |
147 | 71ba1ca3 | gaqhf | return result; |
148 | 1ed39474 | gaqhf | } |
149 | 69b7387a | gaqhf | } |
150 | } |