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