hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 3e5292ae
이력 | 보기 | 이력해설 | 다운로드 (9.79 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 |
Ingr.RAD2D.Application radApp; |
31 |
dynamic application; |
32 |
public ConverterDocking() |
33 |
{ |
34 |
InitializeComponent(); |
35 |
application = Interaction.GetObject("", "PIDAutomation.Application"); |
36 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
37 |
radApp = wApp.RADApplication; |
38 |
|
39 |
try |
40 |
{ |
41 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
42 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
43 |
} |
44 |
catch (Exception ex) |
45 |
{ |
46 |
StringBuilder sb = new StringBuilder(); |
47 |
sb.AppendLine(ex.Message); |
48 |
sb.AppendLine(ex.StackTrace); |
49 |
MessageBox.Show(sb.ToString()); |
50 |
} |
51 |
|
52 |
#if DEBUG |
53 |
simpleButton1.Visible = true; |
54 |
|
55 |
|
56 |
#endif |
57 |
} |
58 |
|
59 |
private void btnConverter_Click(object sender, EventArgs e) |
60 |
{ |
61 |
ConverterForm converterForm = new ConverterForm(); |
62 |
if (converterForm.ShowDialog() == DialogResult.OK) |
63 |
{ |
64 |
try |
65 |
{ |
66 |
CloseOPCForm.Run(); |
67 |
|
68 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
69 |
{ |
70 |
SPPID_Document document = converterForm.Documents[i]; |
71 |
if (document.SetSPPIDMapping() && document.Enable) |
72 |
{ |
73 |
AutoModeling modeling = new AutoModeling(document, application, radApp); |
74 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
75 |
modeling.Run(); |
76 |
} |
77 |
} |
78 |
} |
79 |
catch (Exception ex) |
80 |
{ |
81 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
82 |
} |
83 |
finally |
84 |
{ |
85 |
CloseOPCForm.Stop(); |
86 |
} |
87 |
|
88 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
89 |
} |
90 |
} |
91 |
|
92 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
93 |
{ |
94 |
LMADataSource dataSource = new LMADataSource(); |
95 |
LMDrawings drawings = new LMDrawings(); |
96 |
|
97 |
//try |
98 |
{ |
99 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
100 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
101 |
if (Project_DB.ConnTestAndCreateTable()) |
102 |
{ |
103 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
104 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
105 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
106 |
else |
107 |
SPPID_DBInfo.Clear(); |
108 |
|
109 |
SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance(); |
110 |
if (sPPID_DBInfo.Enable) |
111 |
{ |
112 |
drawings.Collect(dataSource); |
113 |
|
114 |
DataTable drawingTable = Project_DB.SelectDrawingInfo(); |
115 |
drawingTable.Columns.Add("EXIST", typeof(bool)); |
116 |
drawingTable.Columns.Add("SPPIDPATH", typeof(string)); |
117 |
|
118 |
foreach (LMDrawing item in drawings) |
119 |
{ |
120 |
DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value())); |
121 |
foreach (DataRow row in rows) |
122 |
{ |
123 |
row["EXIST"] = true; |
124 |
row["DRAWINGNAME"] = item.Attributes["Name"].get_Value(); |
125 |
row["SPPIDPATH"] = item.get_Path(); |
126 |
} |
127 |
} |
128 |
|
129 |
List<SPPID_Document> allDocuments = new List<SPPID_Document>(); |
130 |
foreach (DataRow row in drawingTable.Rows) |
131 |
allDocuments.Add((SPPID_Document)row["DOCUMENT"]); |
132 |
|
133 |
AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp); |
134 |
opc.Run(); |
135 |
} |
136 |
} |
137 |
else |
138 |
{ |
139 |
MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
140 |
} |
141 |
} |
142 |
//catch (Exception ex) |
143 |
{ |
144 |
//MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
145 |
} |
146 |
//finally |
147 |
{ |
148 |
ReleaseCOMObjects(dataSource); |
149 |
ReleaseCOMObjects(drawings); |
150 |
} |
151 |
} |
152 |
|
153 |
public void ReleaseCOMObjects(params object[] objVars) |
154 |
{ |
155 |
int intNewRefCount = 0; |
156 |
foreach (object obj in objVars) |
157 |
{ |
158 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
159 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
160 |
} |
161 |
} |
162 |
|
163 |
|
164 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
165 |
{ |
166 |
if (radApp.ActiveSelectSet.Count > 0) |
167 |
{ |
168 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
169 |
if (line2D != null) |
170 |
{ |
171 |
double minX = 0; |
172 |
double minY = 0; |
173 |
double maxX = 0; |
174 |
double maxY = 0; |
175 |
line2D.Range(out minX, out minY, out maxX, out maxY); |
176 |
|
177 |
Settings.Default.DrawingX = maxX - minX; |
178 |
Settings.Default.DrawingY = maxY - minY; |
179 |
Settings.Default.Save(); |
180 |
|
181 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
182 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
183 |
} |
184 |
else |
185 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
186 |
} |
187 |
else |
188 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
189 |
} |
190 |
|
191 |
private void simpleButton1_Click(object sender, EventArgs e) |
192 |
{ |
193 |
|
194 |
foreach (var item1 in radApp.ActiveDocument.ActiveSheet.Symbols) |
195 |
{ |
196 |
foreach (var attributes in item1.AttributeSets) |
197 |
{ |
198 |
foreach (var att in attributes) |
199 |
{ |
200 |
if (att.Name == "ModelID") |
201 |
{ |
202 |
string modelItemID = att.GetValue().ToString(); |
203 |
} |
204 |
} |
205 |
} |
206 |
} |
207 |
|
208 |
foreach (var item1 in radApp.ActiveDocument.ActiveSheet.AllDependencyObjects) |
209 |
{ |
210 |
foreach (var attributes in item1.AttributeSets) |
211 |
{ |
212 |
foreach (var att in attributes) |
213 |
{ |
214 |
if (att.Name == "ModelID") |
215 |
{ |
216 |
string modelItemID = att.GetValue().ToString(); |
217 |
} |
218 |
} |
219 |
} |
220 |
} |
221 |
|
222 |
return; |
223 |
Placement _placement = new Placement(); |
224 |
LMADataSource dataSource = new LMADataSource();//placement.PIDDataSource; |
225 |
|
226 |
_LMAItem item = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
227 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
228 |
placeRunInputs.AddPoint(0, 0); |
229 |
placeRunInputs.AddPoint(0.01, 0); |
230 |
placeRunInputs.AddPoint(0.01, -0.01); |
231 |
LMConnector cc = _placement.PIDPlaceRun(item, placeRunInputs); |
232 |
|
233 |
_LMAItem item2 = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
234 |
PlaceRunInputs placeRunInputs2 = new PlaceRunInputs(); |
235 |
placeRunInputs2.AddPoint(0.02, 0); |
236 |
placeRunInputs2.AddConnectorTarget(cc, 0.01, 0); |
237 |
LMConnector cc2 =_placement.PIDPlaceRun(item2, placeRunInputs2); |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
_LMAItem item3 = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
244 |
PlaceRunInputs placeRunInputs3 = new PlaceRunInputs(); |
245 |
placeRunInputs3.AddPoint(0.01, 0.01); |
246 |
if (cc2.ConnectItem1SymbolObject != null) |
247 |
{ |
248 |
placeRunInputs3.AddSymbolTarget(cc2.ConnectItem1SymbolObject, 0.01, 0); |
249 |
} |
250 |
else if (cc2.ConnectItem2SymbolObject != null) |
251 |
{ |
252 |
placeRunInputs3.AddSymbolTarget(cc2.ConnectItem2SymbolObject, 0.01, 0); |
253 |
} |
254 |
|
255 |
_placement.PIDPlaceRun(item3, placeRunInputs3); |
256 |
|
257 |
} |
258 |
[DllImport("user32.dll")] |
259 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
260 |
|
261 |
[DllImport("user32.dll", SetLastError = true)] |
262 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
263 |
|
264 |
} |
265 |
} |