개정판 4941f5fe
dev issue #507 : memory release 추가
Change-Id: Ibe66ff7c7a26f66d0eaa5e9006055abfbd17f087
DTI_PID/SPPIDConverter/ConverterDocking.cs | ||
---|---|---|
22 | 22 |
using DevExpress.XtraSplashScreen; |
23 | 23 |
using Newtonsoft.Json; |
24 | 24 |
using System.Runtime.InteropServices; |
25 |
using System.Reflection; |
|
25 | 26 |
|
26 | 27 |
namespace Converter.SPPID.Wrapper |
27 | 28 |
{ |
28 | 29 |
public partial class ConverterDocking : UserControl |
29 | 30 |
{ |
30 |
|
|
31 |
Ingr.RAD2D.Application application; |
|
31 | 32 |
public ConverterDocking() |
32 | 33 |
{ |
33 | 34 |
InitializeComponent(); |
35 |
|
|
36 |
dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
|
37 |
WrapperApplication wApp = new WrapperApplication(dApplication.Application); |
|
38 |
application = wApp.RADApplication; |
|
34 | 39 |
|
35 |
|
|
40 |
ReleaseCOMObjects(dApplication); |
|
41 |
dApplication = null; |
|
36 | 42 |
try |
37 | 43 |
{ |
38 | 44 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
... | ... | |
58 | 64 |
ConverterForm converterForm = new ConverterForm(); |
59 | 65 |
if (converterForm.ShowDialog() == DialogResult.OK) |
60 | 66 |
{ |
67 |
//Ingr.RAD2D.Document doc = application.Documents.Add(); |
|
68 |
|
|
61 | 69 |
try |
62 | 70 |
{ |
63 | 71 |
CloseOPCForm.Run(); |
... | ... | |
67 | 75 |
SPPID_Document document = converterForm.Documents[i]; |
68 | 76 |
if (document.SetSPPIDMapping() && document.Enable) |
69 | 77 |
{ |
70 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
|
71 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
|
72 |
Ingr.RAD2D.Application radApp = wApp.RADApplication; |
|
73 |
|
|
74 |
AutoModeling modeling = new AutoModeling(document, application, radApp, converterForm.checkEditCloseDocument.Checked); |
|
78 |
AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked); |
|
75 | 79 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
76 | 80 |
modeling.Run(); |
77 |
|
|
78 |
ReleaseCOMObjects(application); |
|
79 | 81 |
} |
80 | 82 |
} |
81 | 83 |
} |
... | ... | |
86 | 88 |
finally |
87 | 89 |
{ |
88 | 90 |
CloseOPCForm.Stop(); |
91 |
|
|
92 |
//doc.SaveOnClose = false; |
|
93 |
//doc.Close(false); |
|
94 |
|
|
95 |
//dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application"); |
|
96 |
//dApplication.Drawings[1].CloseDrawing(false); |
|
97 |
//ReleaseCOMObjects(dApplication); |
|
98 |
//dApplication = null; |
|
89 | 99 |
} |
90 | 100 |
|
91 | 101 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
... | ... | |
94 | 104 |
|
95 | 105 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
96 | 106 |
{ |
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); |
|
107 |
if (application.ActiveDocument == null) |
|
108 |
application.Documents.Add(); |
|
120 | 109 |
|
121 |
DataTable drawingTable = Project_DB.SelectDrawingInfo();
|
|
122 |
drawingTable.Columns.Add("EXIST", typeof(bool));
|
|
123 |
drawingTable.Columns.Add("SPPIDPATH", typeof(string));
|
|
110 |
//dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
|
|
111 |
//WrapperApplication wApp = new WrapperApplication(application.Application);
|
|
112 |
//Ingr.RAD2D.Application radApp = wApp.RADApplication;
|
|
124 | 113 |
|
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 |
} |
|
114 |
//LMADataSource dataSource = new LMADataSource(); |
|
115 |
//LMDrawings drawings = new LMDrawings(); |
|
135 | 116 |
|
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 |
} |
|
117 |
////try |
|
118 |
//{ |
|
119 |
// Project_Info _ProjectInfo = Project_Info.GetInstance(); |
|
120 |
// _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
|
121 |
// if (Project_DB.ConnTestAndCreateTable()) |
|
122 |
// { |
|
123 |
// DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
|
124 |
// if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
|
125 |
// SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
|
126 |
// else |
|
127 |
// SPPID_DBInfo.Clear(); |
|
128 |
|
|
129 |
// SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance(); |
|
130 |
// if (sPPID_DBInfo.Enable) |
|
131 |
// { |
|
132 |
// drawings.Collect(dataSource); |
|
133 |
|
|
134 |
// DataTable drawingTable = Project_DB.SelectDrawingInfo(); |
|
135 |
// drawingTable.Columns.Add("EXIST", typeof(bool)); |
|
136 |
// drawingTable.Columns.Add("SPPIDPATH", typeof(string)); |
|
137 |
|
|
138 |
// foreach (LMDrawing item in drawings) |
|
139 |
// { |
|
140 |
// DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value())); |
|
141 |
// foreach (DataRow row in rows) |
|
142 |
// { |
|
143 |
// row["EXIST"] = true; |
|
144 |
// row["DRAWINGNAME"] = item.Attributes["Name"].get_Value(); |
|
145 |
// row["SPPIDPATH"] = item.get_Path(); |
|
146 |
// } |
|
147 |
// } |
|
148 |
|
|
149 |
// List<SPPID_Document> allDocuments = new List<SPPID_Document>(); |
|
150 |
// foreach (DataRow row in drawingTable.Rows) |
|
151 |
// allDocuments.Add((SPPID_Document)row["DOCUMENT"]); |
|
152 |
|
|
153 |
// AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp); |
|
154 |
// opc.Run(); |
|
155 |
// } |
|
156 |
// } |
|
157 |
// else |
|
158 |
// { |
|
159 |
// MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
|
160 |
// } |
|
161 |
//} |
|
162 |
////catch (Exception ex) |
|
163 |
//{ |
|
164 |
// //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
|
165 |
//} |
|
166 |
////finally |
|
167 |
//{ |
|
168 |
// ReleaseCOMObjects(dataSource); |
|
169 |
// ReleaseCOMObjects(drawings); |
|
170 |
//} |
|
158 | 171 |
} |
159 | 172 |
|
160 | 173 |
public void ReleaseCOMObjects(params object[] objVars) |
... | ... | |
199 | 212 |
} |
200 | 213 |
|
201 | 214 |
#region TEST |
202 |
Placement _placement = new Placement(); |
|
203 |
LMADataSource dataSource; |
|
204 |
bool first = true; |
|
205 |
LMDrawing currentDrawing; |
|
206 | 215 |
private void simpleButton1_Click(object sender, EventArgs e) |
207 | 216 |
{ |
208 |
dataSource = _placement.PIDDataSource; |
|
217 |
Thread outThread = new Thread(func2 => |
|
218 |
{ |
|
219 |
for (int i = 100; i < 120; i++) |
|
220 |
{ |
|
221 |
Thread thread = new Thread(func => |
|
222 |
{ |
|
223 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
|
224 |
//WrapperApplication wApp = new WrapperApplication(application.Application); |
|
225 |
//Ingr.RAD2D.Application radApp = wApp.RADApplication; |
|
226 |
dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123"); |
|
227 |
|
|
228 |
Thread.Sleep(5000); |
|
229 |
|
|
230 |
drawing.CloseDrawing(true); |
|
231 |
|
|
232 |
//application.Quit(); |
|
233 |
ReleaseCOMObjects(application); |
|
234 |
application = null; |
|
235 |
ReleaseCOMObjects(drawing); |
|
236 |
drawing = null; |
|
237 |
Thread.Sleep(5000); |
|
238 |
}); |
|
239 |
thread.Start(); |
|
240 |
thread.Join(); |
|
241 |
} |
|
242 |
}); |
|
243 |
outThread.Start(); |
|
244 |
|
|
245 |
|
|
246 |
|
|
209 | 247 |
|
210 |
string projectNumber = dataSource.ProjectNumber; |
|
211 |
LMActiveProject activeProject = dataSource.GetActiveProject(); |
|
212 |
LMAEnumAttLists enumAttLists = dataSource.CodeLists; |
|
213 | 248 |
|
214 |
AutoJoinPipeRun(); |
|
249 |
//radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid"); |
|
250 |
|
|
251 |
//radApp.ActiveDocument.Close(true); |
|
252 |
//drawing.CloseDrawing(true); |
|
253 |
|
|
254 |
//ReleaseCOMObjects(application); |
|
255 |
//ReleaseCOMObjects(drawing); |
|
256 |
//application = null; |
|
257 |
//wApp = null; |
|
258 |
//radApp = null; |
|
259 |
//drawing = null; |
|
215 | 260 |
} |
261 |
|
|
216 | 262 |
private void AutoJoinPipeRun() |
217 | 263 |
{ |
218 | 264 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
... | ... | |
237 | 283 |
} |
238 | 284 |
radApp.ActiveSelectSet.RemoveAll(); |
239 | 285 |
|
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 | 286 |
} |
428 | 287 |
#endregion |
429 | 288 |
|
내보내기 Unified diff