프로젝트

일반

사용자정보

개정판 a80baec5

IDa80baec5948dabdfbfcd470db15f49422a50afd8
상위 b7354ec1
하위 9c242f1b

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

dev issue #507 : fix opc

Change-Id: I7385d4378877a104eb8a22f0c3d885541afea616

차이점 보기:

DTI_PID/DTI_PID.sln
1 1

2 2
Microsoft Visual Studio Solution File, Format Version 12.00
3
# Visual Studio 15
4
VisualStudioVersion = 15.0.26430.14
3
# Visual Studio Version 16
4
VisualStudioVersion = 16.0.29613.14
5 5
MinimumVisualStudioVersion = 10.0.40219.1
6 6
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "DTI_PID", "DTI_PID\DTI_PID.pyproj", "{7C2E55A3-2B16-4B4F-867F-F16E2EF6F2F0}"
7 7
EndProject
DTI_PID/SPPIDConverter/ConverterDocking.cs
204 204

  
205 205
        private void btnLinkOPC_Click(object sender, EventArgs e)
206 206
        {
207
            DataTable tOPCInfo = Project_DB.SelectOPCInfo();
208
            DataTable tOPCRelations = Project_DB.SelectOPCRelations();
209
            DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
210
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
207
            Placement placement = new Placement();
208
            LMADataSource dataSource = placement.PIDDataSource;
209

  
210
            LMPlantSettings plantSettings = new LMPlantSettings();
211
            plantSettings.Collect(dataSource);
212
            string settingValue = SPPIDUtil.T_PLANTSETTING_Value("Plant Path");
213

  
214
            if (string.IsNullOrEmpty(settingValue))
215
                return;
216
            
217
            LMAFilter filter = new LMAFilter();
218
            LMACriterion criterion = new LMACriterion();
219
            filter.ItemType = "Drawing";
220
            criterion.SourceAttributeName = "Name";
221
            criterion.Operator = "=";
222
            criterion.set_ValueAttribute(application.ActiveDocument.Name.Replace(".pid", ""));
223
            filter.get_Criteria().Add(criterion);
211 224

  
212
            foreach (DataRow row in tOPCInfo.Rows)
225
            LMDrawings drawings = new LMDrawings();
226
            drawings.Collect(dataSource, Filter: filter);
227

  
228
            // Input Drawing Attribute
229
            LMDrawing drawing = ((dynamic)drawings).Nth(1);
230

  
231
            LMAFilter filter2 = new LMAFilter();
232
            filter2.ItemType = "REPRESENTATION";
233

  
234
            LMACriterion criterion2 = new LMACriterion();
235
            criterion2.SourceAttributeName = "REPRESENTATIONTYPE";
236
            criterion2.Operator = "=";
237
            criterion2.set_ValueAttribute("39");
238
            filter2.get_Criteria().Add(criterion2);
239

  
240
            LMRepresentations representations = new LMRepresentations();
241
            representations.Collect(dataSource, Filter: filter2);
242

  
243
            string drawingID = drawing.Id;
244
            List<Tuple<LMRepresentation, string>> CurrentDrawing = new List<Tuple<LMRepresentation, string>>();
245
            List<Tuple<LMRepresentation, string>> OtherDrawing = new List<Tuple<LMRepresentation, string>>(); 
246
            foreach (LMRepresentation representation in representations)
213 247
            {
214
                if (!Convert.ToBoolean(row["PAIRED"]))
248
                if (representation.get_ItemStatus() == "Active" && representation.get_InStockpile() == "False")
215 249
                {
216
                    string drawingUID = row["ID2_DRAWING_UID"].ToString();
217
                    string OPCUID = row["ID2_OPC_UID"].ToString();
218
                    DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID));
250
                    LMSymbol symbol = dataSource.GetSymbol(representation.Id);
219 251

  
220
                    if (rows.Length == 2)
252
                    if (symbol != null)
221 253
                    {
222
                        string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
223
                        string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
224
                        string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
225
                        string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
226
                        string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
227
                        string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
228
                        string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
229
                        string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
230

  
231
                        DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
232
                        DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
233
                        DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
234
                        DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
235

  
236
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
254
                        string sResult = "";
255
                        bool bResult = true;
256
                        foreach (LMConnector item in symbol.Connect1Connectors)
237 257
                        {
238
                            DataRow fromOPCInfoRow = fromOPCInfoRows[0];
239
                            DataRow toOPCInfoRow = toOPCInfoRows[0];
240
                            string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
241
                            string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
242
                            string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
243
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
244
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
245
                            if (opc.Run())
258
                            if (item.get_ItemStatus() == "Active" && item.get_InStockpile() == "False" && item.ModelItemObject.get_ItemTypeName() == "PipeRun")
246 259
                            {
247
                                fromOPCInfoRow["PAIRED"] = true;
248
                                toOPCInfoRow["PAIRED"] = true;
249

  
250
                                Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
251
                                Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
260
                                LMPipeRun pipeRun = dataSource.GetPipeRun(item.ModelItemID);
261
                                if (pipeRun != null)
262
                                {
263
                                    dynamic value = pipeRun.get_ItemTag();
264
                                    if (!DBNull.Value.Equals(value))
265
                                    {
266
                                        if (string.IsNullOrEmpty(sResult))
267
                                            sResult = value;
268
                                        else
269
                                            bResult = false;
270
                                    }
271
                                }
272
                                ReleaseCOMObjects(pipeRun);
252 273
                            }
253 274
                        }
275
                        foreach (LMConnector item in symbol.Connect2Connectors)
276
                        {
277
                            if (item.get_ItemStatus() == "Active" && item.get_InStockpile() == "False" && item.ModelItemObject.get_ItemTypeName() == "PipeRun")
278
                            {
279
                                LMPipeRun pipeRun = dataSource.GetPipeRun(item.ModelItemID);
280
                                if (pipeRun != null)
281
                                {
282
                                    dynamic value = pipeRun.get_ItemTag();
283
                                    if (!DBNull.Value.Equals(value))
284
                                    {
285
                                        if (string.IsNullOrEmpty(sResult))
286
                                            sResult = value;
287
                                        else
288
                                            bResult = false;
289
                                    }
290
                                }
291
                                ReleaseCOMObjects(pipeRun);
292
                            }
293
                        }
294

  
295
                        if (bResult)
296
                        {
297
                            if (representation.DrawingID == drawingID)
298
                                CurrentDrawing.Add(new Tuple<LMRepresentation, string>(representation, sResult));
299
                            else
300
                                OtherDrawing.Add(new Tuple<LMRepresentation, string>(representation, sResult));
301
                        }
254 302
                    }
303

  
304
                    ReleaseCOMObjects(symbol);
255 305
                }
256 306
            }
257 307

  
258
            tOPCInfo.Dispose();
259
            tOPCRelations.Dispose();
260
            tDrawingInfo.Dispose();
261
            ReleaseCOMObjects(dApplication);
262
            dApplication = null;
308
            List<OPC_Info> _OPC_Infos = new List<OPC_Info>();
309

  
310
            foreach (var current in CurrentDrawing)
311
            {
312
                LMOPC currentOPC = dataSource.GetOPC(current.Item1.ModelItemID);
313
                string fileName = current.Item1.get_FileName();
314
                string tag = current.Item2;
315
                List<LMOPC> findOPCs = new List<LMOPC>(); 
316
                foreach (var other in OtherDrawing)
317
                {
318
                    if (tag == other.Item2 && fileName == other.Item1.get_FileName())
319
                    {
320
                        LMOPC otherOPC = dataSource.GetOPC(other.Item1.ModelItemID);
321
                        findOPCs.Add(otherOPC);
322
                    }
323
                }
324

  
325
                if (findOPCs.Count == 1)
326
                {
327
                    LMRepresentation currentPairRepresentation = currentOPC.pairedWithOPCObject.Representations.Nth[1];
328
                    LMRepresentation findPairRepresentation = findOPCs[0].pairedWithOPCObject.Representations.Nth[1];
329
                    if (currentPairRepresentation == null || findPairRepresentation == null)
330
                        continue;
331
                    else if (currentPairRepresentation.get_ItemStatus() == "Active" && currentPairRepresentation.get_InStockpile() == "True" &&
332
                        findPairRepresentation.get_ItemStatus() == "Active" && findPairRepresentation.get_InStockpile() == "True")
333
                    {
334
                        string currentGraphicOID = currentOPC.Representations.Nth[1].get_GraphicOID().ToString();
335
                        LMRepresentation findRepresentation = findOPCs[0].Representations.Nth[1];
336
                        string findGraphicOID = findRepresentation.get_GraphicOID().ToString();
337
                        LMDrawing findDrawing = findRepresentation.DrawingObject;
338
                        string findDrawingPath = settingValue + findDrawing.get_Path();
339

  
340
                        _OPC_Infos.Add(new OPC_Info()
341
                        {
342
                            CurrentGraphicOID = currentGraphicOID,
343
                            TagValue = tag,
344
                            FindGraphicOID = findGraphicOID,
345
                            FindDrawingPath = findDrawingPath,
346
                            FindDrawingName = Path.GetFileNameWithoutExtension(findDrawingPath),
347
                            CurrentRepID = currentOPC.Representations.Nth[1].Id,
348
                            FindRepID = findRepresentation.Id
349
                        });
350

  
351
                        ReleaseCOMObjects(findDrawing);
352
                        ReleaseCOMObjects(findRepresentation);
353

  
354
                        //application.ActiveSelectSet.Add(application.ActiveDocument.ActiveSheet.DrawingObjects[currentOPC.Representations.Nth[1].get_GraphicOID().ToString()]);
355
                    }
356
                }
357

  
358
                foreach (var item in findOPCs)
359
                    ReleaseCOMObjects(item);
360
                ReleaseCOMObjects(currentOPC);
361
            }
362

  
363
            if (_OPC_Infos.Count > 0)
364
            {
365
                foreach (var item in _OPC_Infos)
366
                {
367
                    LMRepresentation removeRep = dataSource.GetRepresentation(item.CurrentRepID);
368
                    LMSymbol removeSymbol = dataSource.GetSymbol(item.CurrentRepID);
369
                    LMOPC removeOPC = dataSource.GetOPC(removeSymbol.ModelItemID);
370

  
371
                    
372

  
373
                    LMRepresentation findRep = dataSource.GetRepresentation(item.FindRepID);
374
                    LMOPC findOPC = dataSource.GetOPC(findRep.ModelItemID);
375
                    LMOPC pairOPC = findOPC.pairedWithOPCObject;
376

  
377
                    int mirror = removeSymbol.get_IsMirroredIndex();
378
                    double angle = Convert.ToDouble(removeSymbol.get_RotationAngle());
379
                    double x = removeSymbol.get_XCoordinate();
380
                    double y = removeSymbol.get_YCoordinate();
381
                    LMConnector connConnector = null;
382
                    
383
                    foreach (LMConnector connector in removeSymbol.Connect1Connectors)
384
                        if (connector.get_ItemStatus() == "Active")
385
                            connConnector = connector;
386
                    if (connConnector == null)
387
                        foreach (LMConnector connector in removeSymbol.Connect2Connectors)
388
                            if (connector.get_ItemStatus() == "Active")
389
                                connConnector = connector;
390
                    
391
                    if (connConnector != null)
392
                    {
393
                        ZoomObjectByGraphicOID(removeRep.get_GraphicOID().ToString());
394

  
395
                        placement.PIDRemovePlacement(removeRep);
396
                        removeRep.Commit();
397

  
398
                        LMSymbol newSymbol = placement.PIDPlaceSymbol(findRep.get_FileName(), x, y, mirror, angle, pairOPC.AsLMAItem(), connConnector);
399
                        newSymbol.Commit();
400

  
401
                        LMOPC newOPC = dataSource.GetOPC(newSymbol.ModelItemID);
402
                        object descValue = removeOPC.get_Description();
403
                        object toFromValue = removeOPC.get_ToFromText();
404
                        newOPC.set_Description(descValue);
405
                        newOPC.set_ToFromText(toFromValue);
406
                        newOPC.Commit();
407

  
408
                        ReleaseCOMObjects(newSymbol);
409
                        ReleaseCOMObjects(newOPC);
410
                    }
411

  
412
                    ReleaseCOMObjects(findOPC);
413
                    ReleaseCOMObjects(pairOPC);
414
                    ReleaseCOMObjects(findRep);
415
                    ReleaseCOMObjects(removeOPC);
416
                    ReleaseCOMObjects(removeSymbol);
417
                    ReleaseCOMObjects(removeRep);
418
                    ReleaseCOMObjects(connConnector);
419
                }
420

  
421
                application.ActiveDocument.Save();
422
            }
423

  
424

  
425
            foreach (var item in CurrentDrawing)
426
                ReleaseCOMObjects(item);
427
            foreach (var item in OtherDrawing)
428
                ReleaseCOMObjects(item);
429

  
430
            ReleaseCOMObjects(representations);
431

  
432
            ReleaseCOMObjects(filter2);
433
            ReleaseCOMObjects(criterion2);
434
            ReleaseCOMObjects(drawing);
435
            ReleaseCOMObjects(drawings);
436
            ReleaseCOMObjects(filter);
437
            ReleaseCOMObjects(criterion);
438

  
439
            ReleaseCOMObjects(dataSource);
440
            ReleaseCOMObjects(placement);
441

  
442
            return;
263 443

  
264
            MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
444
            //DataTable tOPCInfo = Project_DB.SelectOPCInfo();
445
            //DataTable tOPCRelations = Project_DB.SelectOPCRelations();
446
            //DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
447
            //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
448

  
449
            //foreach (DataRow row in tOPCInfo.Rows)
450
            //{
451
            //    if (!Convert.ToBoolean(row["PAIRED"]))
452
            //    {
453
            //        string drawingUID = row["ID2_DRAWING_UID"].ToString();
454
            //        string OPCUID = row["ID2_OPC_UID"].ToString();
455
            //        DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID));
456

  
457
            //        if (rows.Length == 2)
458
            //        {
459
            //            string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
460
            //            string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
461
            //            string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
462
            //            string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
463
            //            string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
464
            //            string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
465
            //            string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
466
            //            string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
467

  
468
            //            DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
469
            //            DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
470
            //            DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
471
            //            DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
472

  
473
            //            if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
474
            //            {
475
            //                DataRow fromOPCInfoRow = fromOPCInfoRows[0];
476
            //                DataRow toOPCInfoRow = toOPCInfoRows[0];
477
            //                string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
478
            //                string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
479
            //                string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
480
            //                List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
481
            //                AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
482
            //                if (opc.Run())
483
            //                {
484
            //                    fromOPCInfoRow["PAIRED"] = true;
485
            //                    toOPCInfoRow["PAIRED"] = true;
486

  
487
            //                    Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
488
            //                    Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
489
            //                }
490
            //            }
491
            //        }
492
            //    }
493
            //}
494

  
495
            //tOPCInfo.Dispose();
496
            //tOPCRelations.Dispose();
497
            //tDrawingInfo.Dispose();
498
            //ReleaseCOMObjects(dApplication);
499
            //dApplication = null;
500

  
501
            //MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
265 502
        }
266 503

  
267 504
        public void ReleaseCOMObjects(params object[] objVars)
DTI_PID/SPPIDConverter/OPC/OPC_Info.cs
8 8
{
9 9
    public class OPC_Info
10 10
    {
11

  
11
        public string CurrentGraphicOID { get; set; }
12
        public string FindGraphicOID { get; set; }
13
        public string FindDrawingPath { get; set; }
14
        public string FindDrawingName { get; set; }
15
        public string TagValue { get; set; }
16
        public string CurrentRepID { get; set; }
17
        public string FindRepID { get; set; }
12 18
    }
13 19
}
DTI_PID/SPPIDConverter/Util/SPPIDUtil.cs
718 718
            return result;
719 719
        }
720 720

  
721
        public static string T_PLANTSETTING_Value(string name)
722
        {
723
            string result = string.Empty;
724
            LMADataSource dataSource = new LMADataSource();
725
            LMPlantSettings settings = new LMPlantSettings();
726

  
727
            LMAFilter filter = new LMAFilter();
728
            LMACriterion criterion = new LMACriterion();
729
            filter.ItemType = "PlantSetting";
730
            criterion.SourceAttributeName = "NAME";
731
            criterion.Operator = "=";
732
            criterion.set_ValueAttribute(name);
733
            filter.get_Criteria().Add(criterion);
734
            settings.Collect(dataSource, Filter: filter);
735

  
736
            foreach (LMPlantSetting item in settings)
737
            {
738
                result = item.get_Value();
739
                break;
740
            }
741

  
742
            ReleaseCOMObjects(criterion);
743
            ReleaseCOMObjects(filter);
744
            ReleaseCOMObjects(settings);
745
            ReleaseCOMObjects(dataSource);
746
            return result;
747
        }
748

  
721 749
        public static void ReleaseCOMObjects(params object[] objVars)
722 750
        {
723 751
            int intNewRefCount = 0;

내보내기 Unified diff

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