개정판 4941f5fe
dev issue #507 : memory release 추가
Change-Id: Ibe66ff7c7a26f66d0eaa5e9006055abfbd17f087
DTI_PID/SPPIDConverter/AutoModeling.cs | ||
---|---|---|
28 | 28 |
{ |
29 | 29 |
Placement _placement; |
30 | 30 |
LMADataSource dataSource; |
31 |
LMDrawing currentDrawing;
|
|
31 |
string drawingID;
|
|
32 | 32 |
dynamic newDrawing; |
33 | 33 |
dynamic application; |
34 | 34 |
bool closeDocument; |
... | ... | |
44 | 44 |
List<string> ZeroLengthModelItemIDReverse = new List<string>(); |
45 | 45 |
List<Symbol> prioritySymbols; |
46 | 46 |
|
47 |
public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp, bool closeDocument)
|
|
47 |
public AutoModeling(SPPID_Document document, bool closeDocument) |
|
48 | 48 |
{ |
49 |
application = Interaction.GetObject("", "PIDAutomation.Application"); |
|
50 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
|
51 |
radApp = wApp.RADApplication; |
|
52 |
|
|
49 | 53 |
this.closeDocument = closeDocument; |
50 | 54 |
this.document = document; |
51 |
this.application = application; |
|
52 |
this.radApp = radApp; |
|
53 | 55 |
this._ETCSetting = ETCSetting.GetInstance(); |
54 | 56 |
} |
55 | 57 |
|
... | ... | |
78 | 80 |
string drawingName = document.DrawingName; |
79 | 81 |
try |
80 | 82 |
{ |
81 |
_placement = new Placement(); |
|
82 |
dataSource = _placement.PIDDataSource; |
|
83 |
|
|
84 |
CreateDocument(ref drawingNumber, ref drawingName); |
|
85 |
|
|
86 |
if (DocumentCoordinateCorrection()) |
|
83 |
if (CreateDocument(ref drawingNumber, ref drawingName) && DocumentCoordinateCorrection()) |
|
87 | 84 |
{ |
88 | 85 |
Log.Write("Start Modeling"); |
89 | 86 |
SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
... | ... | |
130 | 127 |
} |
131 | 128 |
catch (Exception ex) |
132 | 129 |
{ |
133 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
|
134 |
SplashScreenManager.CloseForm(false); |
|
130 |
if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
|
131 |
{ |
|
132 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
|
133 |
SplashScreenManager.CloseForm(false); |
|
134 |
Log.Write("\r\n"); |
|
135 |
} |
|
135 | 136 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
136 | 137 |
} |
137 | 138 |
finally |
138 | 139 |
{ |
139 |
Log.Write("End Modeling"); |
|
140 |
application.ActiveWindow.Fit(); |
|
140 |
Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document); |
|
141 |
if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
|
142 |
{ |
|
143 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
|
144 |
SplashScreenManager.CloseForm(false); |
|
145 |
Log.Write("\r\n"); |
|
146 |
} |
|
147 |
Thread.Sleep(1000); |
|
141 | 148 |
|
142 |
if (currentDrawing != null)
|
|
143 |
ReleaseCOMObjects(currentDrawing);
|
|
149 |
Log.Write("End Modeling");
|
|
150 |
radApp.ActiveWindow.Fit();
|
|
144 | 151 |
|
152 |
ReleaseCOMObjects(application); |
|
153 |
application = null; |
|
145 | 154 |
if (radApp.ActiveDocument != null) |
146 | 155 |
{ |
147 |
newDrawing.Save(); |
|
148 |
if (closeDocument) |
|
156 |
if (closeDocument && newDrawing != null) |
|
157 |
{ |
|
158 |
newDrawing.Save(); |
|
149 | 159 |
newDrawing.CloseDrawing(true); |
150 |
ReleaseCOMObjects(newDrawing); |
|
160 |
ReleaseCOMObjects(newDrawing); |
|
161 |
newDrawing = null; |
|
162 |
} |
|
163 |
else if (newDrawing == null) |
|
164 |
{ |
|
165 |
Log.Write("error document"); |
|
166 |
} |
|
151 | 167 |
} |
152 | 168 |
|
153 | 169 |
ReleaseCOMObjects(dataSource); |
170 |
dataSource = null; |
|
154 | 171 |
ReleaseCOMObjects(_placement); |
172 |
_placement = null; |
|
155 | 173 |
|
156 |
Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document); |
|
157 |
if (SplashScreenManager.Default.IsSplashFormVisible) |
|
158 |
{ |
|
159 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
|
160 |
SplashScreenManager.CloseForm(false); |
|
161 |
Log.Write("\r\n"); |
|
162 |
} |
|
163 |
|
|
164 |
GC.Collect(); |
|
174 |
Thread.Sleep(1000); |
|
165 | 175 |
} |
166 | 176 |
} |
177 |
|
|
167 | 178 |
private void RunEquipmentModeling() |
168 | 179 |
{ |
169 | 180 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count); |
... | ... | |
283 | 294 |
filter.ItemType = "Relationship"; |
284 | 295 |
criterion.SourceAttributeName = "SP_DRAWINGID"; |
285 | 296 |
criterion.Operator = "="; |
286 |
criterion.set_ValueAttribute(currentDrawing.Id);
|
|
297 |
criterion.set_ValueAttribute(drawingID);
|
|
287 | 298 |
filter.get_Criteria().Add(criterion); |
288 | 299 |
|
289 | 300 |
LMRelationships relationships = new LMRelationships(); |
... | ... | |
315 | 326 |
loop = true; |
316 | 327 |
attribute1.set_Value(DBNull.Value); |
317 | 328 |
} |
329 |
attribute1 = null; |
|
318 | 330 |
} |
319 | 331 |
else |
320 | 332 |
{ |
... | ... | |
324 | 336 |
loop = true; |
325 | 337 |
attribute1.set_Value(DBNull.Value); |
326 | 338 |
} |
339 |
attribute1 = null; |
|
327 | 340 |
} |
328 | 341 |
modelItem1.Commit(); |
329 | 342 |
} |
... | ... | |
340 | 353 |
attribute2.set_Value(DBNull.Value); |
341 | 354 |
loop = true; |
342 | 355 |
} |
356 |
attribute2 = null; |
|
343 | 357 |
} |
344 | 358 |
else |
345 | 359 |
{ |
... | ... | |
349 | 363 |
attribute2.set_Value(DBNull.Value); |
350 | 364 |
loop = true; |
351 | 365 |
} |
366 |
attribute2 = null; |
|
352 | 367 |
} |
353 | 368 |
modelItem2.Commit(); |
354 | 369 |
} |
355 |
if (modelItem1 != null)
|
|
356 |
ReleaseCOMObjects(modelItem1);
|
|
357 |
if (modelItem2 != null)
|
|
358 |
ReleaseCOMObjects(modelItem2);
|
|
370 |
ReleaseCOMObjects(modelItem1);
|
|
371 |
modelItem1 = null;
|
|
372 |
ReleaseCOMObjects(modelItem2);
|
|
373 |
modelItem2 = null;
|
|
359 | 374 |
inconsistency.Commit(); |
360 | 375 |
} |
376 |
ReleaseCOMObjects(inconsistency); |
|
361 | 377 |
} |
362 | 378 |
relationship.Commit(); |
379 |
ReleaseCOMObjects(relationship); |
|
363 | 380 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
364 | 381 |
} |
365 | 382 |
ReleaseCOMObjects(filter); |
383 |
filter = null; |
|
366 | 384 |
ReleaseCOMObjects(criterion); |
385 |
criterion = null; |
|
367 | 386 |
ReleaseCOMObjects(relationships); |
387 |
relationships = null; |
|
368 | 388 |
count++; |
369 | 389 |
} |
370 | 390 |
} |
... | ... | |
720 | 740 |
/// <summary> |
721 | 741 |
/// 도면 생성 메서드 |
722 | 742 |
/// </summary> |
723 |
private void CreateDocument(ref string drawingNumber, ref string drawingName)
|
|
743 |
private bool CreateDocument(ref string drawingNumber, ref string drawingName)
|
|
724 | 744 |
{ |
725 | 745 |
Log.Write("------------------ Start create document ------------------"); |
726 | 746 |
GetDrawingNameAndNumber(ref drawingName, ref drawingNumber); |
727 | 747 |
Log.Write("Drawing name : " + drawingName); |
728 | 748 |
Log.Write("Drawing number : " + drawingNumber); |
729 |
newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName); |
|
730 |
document.SPPID_DrawingNumber = drawingNumber; |
|
731 |
document.SPPID_DrawingName = drawingName; |
|
732 | 749 |
Thread.Sleep(1000); |
733 |
application.ActiveWindow.Fit();
|
|
750 |
radApp.RunCommand(Ingr.RAD2D.CommandConstants.igcmdWindowRefresh);
|
|
734 | 751 |
Thread.Sleep(1000); |
735 |
application.ActiveWindow.Zoom = 2000; |
|
736 |
Thread.Sleep(2000); |
|
737 |
|
|
738 |
//current LMDrawing 가져오기 |
|
739 |
LMAFilter filter = new LMAFilter(); |
|
740 |
LMACriterion criterion = new LMACriterion(); |
|
741 |
filter.ItemType = "Drawing"; |
|
742 |
criterion.SourceAttributeName = "Name"; |
|
743 |
criterion.Operator = "="; |
|
744 |
criterion.set_ValueAttribute(drawingName); |
|
745 |
filter.get_Criteria().Add(criterion); |
|
752 |
newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName); |
|
753 |
if (newDrawing != null) |
|
754 |
{ |
|
755 |
document.SPPID_DrawingNumber = drawingNumber; |
|
756 |
document.SPPID_DrawingName = drawingName; |
|
757 |
Thread.Sleep(1000); |
|
758 |
radApp.ActiveWindow.Fit(); |
|
759 |
Thread.Sleep(1000); |
|
760 |
radApp.ActiveWindow.Zoom = 2000; |
|
761 |
Thread.Sleep(2000); |
|
746 | 762 |
|
747 |
LMDrawings drawings = new LMDrawings(); |
|
748 |
drawings.Collect(dataSource, Filter: filter); |
|
763 |
_placement = new Placement(); |
|
764 |
dataSource = _placement.PIDDataSource; |
|
765 |
|
|
766 |
//current LMDrawing 가져오기 |
|
767 |
LMAFilter filter = new LMAFilter(); |
|
768 |
LMACriterion criterion = new LMACriterion(); |
|
769 |
filter.ItemType = "Drawing"; |
|
770 |
criterion.SourceAttributeName = "Name"; |
|
771 |
criterion.Operator = "="; |
|
772 |
criterion.set_ValueAttribute(drawingName); |
|
773 |
filter.get_Criteria().Add(criterion); |
|
774 |
|
|
775 |
LMDrawings drawings = new LMDrawings(); |
|
776 |
drawings.Collect(dataSource, Filter: filter); |
|
749 | 777 |
|
750 |
currentDrawing = ((dynamic)drawings).Nth(1); |
|
778 |
drawingID = ((dynamic)drawings).Nth(1).Id; |
|
779 |
ReleaseCOMObjects(filter); |
|
780 |
ReleaseCOMObjects(criterion); |
|
781 |
ReleaseCOMObjects(drawings); |
|
782 |
filter = null; |
|
783 |
criterion = null; |
|
784 |
drawings = null; |
|
785 |
} |
|
786 |
else |
|
787 |
Log.Write("Fail Create Drawing"); |
|
788 |
|
|
789 |
if (newDrawing != null) |
|
790 |
return true; |
|
791 |
else |
|
792 |
return false; |
|
751 | 793 |
} |
752 | 794 |
|
753 | 795 |
/// <summary> |
... | ... | |
757 | 799 |
/// <param name="drawingNumber"></param> |
758 | 800 |
private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber) |
759 | 801 |
{ |
802 |
LMADataSource dataSource = new LMADataSource(); |
|
760 | 803 |
LMDrawings drawings = new LMDrawings(); |
761 | 804 |
drawings.Collect(dataSource); |
762 | 805 |
|
... | ... | |
794 | 837 |
drawingNumber += ++index; |
795 | 838 |
} |
796 | 839 |
} |
797 |
|
|
840 |
ReleaseCOMObjects(dataSource); |
|
841 |
dataSource = null; |
|
798 | 842 |
ReleaseCOMObjects(drawings); |
843 |
drawings = null; |
|
799 | 844 |
} |
800 | 845 |
|
801 | 846 |
/// <summary> |
내보내기 Unified diff