프로젝트

일반

사용자정보

개정판 4941f5fe

ID4941f5fe7e362067868071045b720c5ab3f81b3e
상위 442bd51e
하위 7a23ea42

gaqhf 이(가) 5년 이상 전에 추가함

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>
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

클립보드 이미지 추가 (최대 크기: 500 MB)