개정판 3d7ff99c
dev issue #507 : add OPC file
Change-Id: I473ce9956f4839550269afbfab491f0c98c8dac2
DTI_PID/SPPIDConverter/AutoModeling_OPC.cs | ||
---|---|---|
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 |
|
|
36 |
public AutoModeling_OPC(List<SPPID_Document> allDocuments, dynamic application, Ingr.RAD2D.Application radApp) |
|
37 |
{ |
|
38 |
this.application = application; |
|
39 |
this.radApp = radApp; |
|
40 |
this.allDocuments = allDocuments; |
|
41 |
} |
|
42 |
|
|
43 |
public void Run() |
|
44 |
{ |
|
45 |
_placement = new Placement(); |
|
46 |
dataSource = _placement.PIDDataSource; |
|
47 |
|
|
48 |
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 |
|
|
61 |
ReleaseCOMObjects(_placement); |
|
62 |
ReleaseCOMObjects(dataSource); |
|
63 |
} |
|
64 |
|
|
65 |
public void PairedOPCModeling(Symbol opc) |
|
66 |
{ |
|
67 |
bool result = false; |
|
68 |
LMOPC _LMOPC = dataSource.GetOPC(opc.SPPID.ModelItemID); |
|
69 |
LMOPC pairOPC = _LMOPC.pairedWithOPCObject; |
|
70 |
|
|
71 |
foreach (LMRepresentation rep in pairOPC.Representations) |
|
72 |
if (rep.DrawingID != "0") |
|
73 |
result = true; |
|
74 |
|
|
75 |
if (!result) |
|
76 |
{ |
|
77 |
// OPC Pair 찾아서 도면 오픈후 Pair 모델링 |
|
78 |
BaseModel.Attribute pathAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "PATH"); |
|
79 |
BaseModel.Attribute linkOPCAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "LinkOPC"); |
|
80 |
|
|
81 |
SPPID_Document targetDocument = allDocuments.Find(x => x.PATH == pathAttribute.VALUE); |
|
82 |
if (targetDocument != null) |
|
83 |
{ |
|
84 |
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 |
} |
|
116 |
} |
|
117 |
|
|
118 |
ReleaseCOMObjects(_LMOPC); |
|
119 |
ReleaseCOMObjects(pairOPC); |
|
120 |
} |
|
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 |
} |
|
131 |
|
|
132 |
private bool OpenDrawing(string drawingName) |
|
133 |
{ |
|
134 |
bool result = false; |
|
135 |
try |
|
136 |
{ |
|
137 |
dynamic doc = application.Drawings.OpenDrawing(drawingName); |
|
138 |
doc.Activate(); |
|
139 |
|
|
140 |
result = true; |
|
141 |
} |
|
142 |
catch (Exception ex) |
|
143 |
{ |
|
144 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
|
145 |
} |
|
146 |
|
|
147 |
return result; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
DTI_PID/SPPIDConverter/OPC/AutoModeling_OPC.cs | ||
---|---|---|
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.OPC |
|
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 |
|
|
36 |
public AutoModeling_OPC(List<SPPID_Document> allDocuments, dynamic application, Ingr.RAD2D.Application radApp) |
|
37 |
{ |
|
38 |
this.application = application; |
|
39 |
this.radApp = radApp; |
|
40 |
this.allDocuments = allDocuments; |
|
41 |
} |
|
42 |
|
|
43 |
public void Run() |
|
44 |
{ |
|
45 |
_placement = new Placement(); |
|
46 |
dataSource = _placement.PIDDataSource; |
|
47 |
|
|
48 |
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 |
|
|
61 |
ReleaseCOMObjects(_placement); |
|
62 |
ReleaseCOMObjects(dataSource); |
|
63 |
} |
|
64 |
|
|
65 |
public void PairedOPCModeling(Symbol opc) |
|
66 |
{ |
|
67 |
bool result = false; |
|
68 |
LMOPC _LMOPC = dataSource.GetOPC(opc.SPPID.ModelItemID); |
|
69 |
LMOPC pairOPC = _LMOPC.pairedWithOPCObject; |
|
70 |
|
|
71 |
foreach (LMRepresentation rep in pairOPC.Representations) |
|
72 |
if (rep.DrawingID != "0") |
|
73 |
result = true; |
|
74 |
|
|
75 |
if (!result) |
|
76 |
{ |
|
77 |
// OPC Pair 찾아서 도면 오픈후 Pair 모델링 |
|
78 |
BaseModel.Attribute pathAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "PATH"); |
|
79 |
BaseModel.Attribute linkOPCAttribute = opc.ATTRIBUTES.Find(x => x.ATTRIBUTE == "LinkOPC"); |
|
80 |
|
|
81 |
SPPID_Document targetDocument = allDocuments.Find(x => x.PATH == pathAttribute.VALUE); |
|
82 |
if (targetDocument != null) |
|
83 |
{ |
|
84 |
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 |
} |
|
116 |
} |
|
117 |
|
|
118 |
ReleaseCOMObjects(_LMOPC); |
|
119 |
ReleaseCOMObjects(pairOPC); |
|
120 |
} |
|
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 |
} |
|
131 |
|
|
132 |
private bool OpenDrawing(string drawingName) |
|
133 |
{ |
|
134 |
bool result = false; |
|
135 |
try |
|
136 |
{ |
|
137 |
dynamic doc = application.Drawings.OpenDrawing(drawingName); |
|
138 |
doc.Activate(); |
|
139 |
|
|
140 |
result = true; |
|
141 |
} |
|
142 |
catch (Exception ex) |
|
143 |
{ |
|
144 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
|
145 |
} |
|
146 |
|
|
147 |
return result; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
DTI_PID/SPPIDConverter/OPC/OPC_Info.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Converter.SPPID.OPC |
|
8 |
{ |
|
9 |
public class OPC_Info |
|
10 |
{ |
|
11 |
|
|
12 |
} |
|
13 |
} |
DTI_PID/SPPIDConverter/SPPIDConverter.csproj | ||
---|---|---|
130 | 130 |
</ItemGroup> |
131 | 131 |
<ItemGroup> |
132 | 132 |
<Compile Include="AutoModeling.cs" /> |
133 |
<Compile Include="AutoModeling_OPC.cs" /> |
|
133 |
<Compile Include="OPC\AutoModeling_OPC.cs" />
|
|
134 | 134 |
<Compile Include="BaseModel\ChildSymbol.cs" /> |
135 | 135 |
<Compile Include="BaseModel\Document.cs" /> |
136 | 136 |
<Compile Include="BaseModel\EndBreak.cs" /> |
... | ... | |
190 | 190 |
<DependentUpon>UnitForm.cs</DependentUpon> |
191 | 191 |
</Compile> |
192 | 192 |
<Compile Include="Log.cs" /> |
193 |
<Compile Include="OPC\OPC_Info.cs" /> |
|
193 | 194 |
<Compile Include="Program.cs" /> |
194 | 195 |
<Compile Include="DB\Project_DB.cs" /> |
195 | 196 |
<Compile Include="DB\Project_Info.cs" /> |
... | ... | |
379 | 380 |
<ItemGroup> |
380 | 381 |
<None Include="Resources\logo_color.png" /> |
381 | 382 |
</ItemGroup> |
383 |
<ItemGroup /> |
|
382 | 384 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
383 | 385 |
<Import Project="..\packages\System.Data.SQLite.Core.1.0.111.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.111.0\build\net46\System.Data.SQLite.Core.targets')" /> |
384 | 386 |
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
내보내기 Unified diff