프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 71ba1ca3

이력 | 보기 | 이력해설 | 다운로드 (143 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Data;
7
using Llama;
8
using Plaice;
9
using Ingr.RAD2D.Interop.RAD2D;
10
using Ingr.RAD2D.Internal;
11
using Ingr.RAD2D.Helper;
12
using Converter.BaseModel;
13
using Converter.SPPID.Model;
14
using Converter.SPPID.Properties;
15
using Converter.SPPID.Util;
16
using Converter.SPPID.DB;
17
using Ingr.RAD2D.MacroControls.CmdCtrl;
18
using Ingr.RAD2D;
19
using System.Windows;
20
using System.Threading;
21
using System.Drawing;
22
using Microsoft.VisualBasic;
23
using Newtonsoft.Json;
24

    
25
using DevExpress.XtraSplashScreen;
26
namespace Converter.SPPID
27
{
28
    public class AutoModeling
29
    {
30
        Placement _placement;
31
        LMADataSource dataSource;
32
        dynamic newDrawing;
33
        dynamic application;
34
        Ingr.RAD2D.Application radApp;
35
        SPPID_Document document;
36
        ETCSetting _ETCSetting;
37

    
38
        public string DocumentLabelText { get; set; }
39

    
40
        int CurrentCount;
41
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42
        List<string> ZeroLengthModelItemID = new List<string>();
43

    
44
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
45
        {
46
            this.document = document;
47
            this.application = application;
48
            this.radApp = radApp;
49
            this._ETCSetting = ETCSetting.GetInstance();
50
        }
51

    
52
        private int CalcProgressCount()
53
        {
54
            int EquipCount = 0;
55
            int SymbolCount = 0;
56
            int LineCount = 0;
57
            int NoteCount = 0;
58
            int TextCount = 0;
59
            int EndBreakCount = 0;
60
            int LineNumberCount = 0;
61

    
62
            EquipCount = document.Equipments.Count;
63
            SymbolCount = document.SYMBOLS.Count;
64
            SymbolCount = SymbolCount * 3;
65
            
66
            foreach (LineNumber lineNumber in document.LINENUMBERS)
67
                foreach (LineRun run in lineNumber.RUNS)
68
                    foreach (var item in run.RUNITEMS)
69
                        if (item.GetType() == typeof(Line))
70
                            LineCount++;
71
            foreach (TrimLine trimLine in document.TRIMLINES)
72
                foreach (LineRun run in trimLine.RUNS)
73
                    foreach (var item in run.RUNITEMS)
74
                        if (item.GetType() == typeof(Line))
75
                            LineCount++;
76

    
77
            LineCount = LineCount * 2;
78
            NoteCount = document.NOTES.Count;
79
            TextCount = document.TEXTINFOS.Count;
80
            EndBreakCount = document.EndBreaks.Count;
81
            LineNumberCount = document.LINENUMBERS.Count;
82
            LineNumberCount = LineNumberCount * 2;
83

    
84
            return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount;
85
        }
86

    
87
        private void SetSystemEditingCommand(bool value)
88
        {
89
            foreach (var item in radApp.Commands)
90
            {
91
                if (item.Argument == "SystemEditingCmd.SystemEditing")
92
                {
93
                    if (item.Checked != value)
94
                    {
95
                        radApp.RunMacro("systemeditingcmd.dll");
96
                        break;
97
                    }
98

    
99
                }
100
            }
101
        }
102

    
103
        /// <summary>
104
        /// 도면 단위당 실행되는 메서드
105
        /// </summary>
106
        public void Run()
107
        {
108
            string drawingNumber = document.DrawingNumber;
109
            string drawingName = document.DrawingName;
110
            try
111
            {
112
                _placement = new Placement();
113
                dataSource = _placement.PIDDataSource;
114

    
115
                CreateDocument(ref drawingNumber, ref drawingName);
116

    
117
                if (DocumentCoordinateCorrection())
118
                {
119
                    int AllCount = CalcProgressCount();
120

    
121
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
122
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount);
123
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
124

    
125
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Priority Symbol Modeling");
126
                    List<Symbol> prioritySymbols = GetPrioritySymbol();
127
                    foreach (var item in prioritySymbols)
128
                        SymbolModelingByPriority(item);
129

    
130
                    // Equipment Modeling
131
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
132
                    foreach (Equipment equipment in document.Equipments)
133
                        EquipmentModeling(equipment);
134

    
135
                    // LineRun Symbol Modeling
136
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling");
137
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
138
                        foreach (LineRun run in lineNumber.RUNS)
139
                            SymbolModelingByRun(run);
140
                    // TrimLineRun Symbol Modeling
141
                    foreach (TrimLine trimLine in document.TRIMLINES)
142
                        foreach (LineRun run in trimLine.RUNS)
143
                            SymbolModelingByRun(run);
144

    
145
                    // LineRun Line Modeling
146
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
147
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
148
                        foreach (LineRun run in lineNumber.RUNS)
149
                            LineModelingByRun(run);
150
                    // TrimLineRun Line Modeling
151
                    foreach (TrimLine trimLine in document.TRIMLINES)
152
                        foreach (LineRun run in trimLine.RUNS)
153
                            LineModelingByRun(run);
154

    
155
                    // Branch Line Modeling
156
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
157
                    foreach (var item in BranchLines)
158
                        BranchLineModeling(item);
159

    
160
                    // EndBreak Modeling
161
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
162
                    foreach (var item in document.EndBreaks)
163
                        EndBreakModeling(item);
164

    
165
                    // SpecBreak Modeling
166
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
167
                    foreach (var item in document.SpecBreaks)
168
                        SpecBreakModeling(item);
169

    
170
                    // LineNumber Modeling
171
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling");
172
                    foreach (var item in document.LINENUMBERS)
173
                        LineNumberModeling(item);
174

    
175
                    // FlowMark Modeling
176
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Flow Mark Modeling");
177
                    foreach (var item in document.LINES)
178
                        FlowMarkModeling(item);
179

    
180
                    // Note Modeling
181
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
182
                    foreach (var item in document.NOTES)
183
                        NoteModeling(item);
184

    
185
                    // Text Modeling
186
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
187
                    foreach (var item in document.TEXTINFOS)
188
                        TextModeling(item);
189

    
190
                    // Input LineNumber Attribute
191
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
192
                    foreach (var item in document.LINENUMBERS)
193
                        InputLineNumberAttribute(item);
194

    
195
                    // Input Symbol Attribute
196
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
197
                    foreach (var item in document.SYMBOLS)
198
                        InputSymbolAttribute(item, item.ATTRIBUTES);
199

    
200
                    // Input SpecBreak Attribute
201
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
202
                    foreach (var item in document.SpecBreaks)
203
                        InputSpecBreakAttribute(item);
204

    
205
                    // Label Symbol Modeling
206
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
207
                    foreach (var item in document.SYMBOLS)
208
                        LabelSymbolModeling(item);
209

    
210
                    // LineRun Line Join
211
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
212
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
213
                        foreach (LineRun run in lineNumber.RUNS)
214
                            JoinRunLine(run);
215
                    // TrimLineRun Line Join
216
                    foreach (TrimLine trimLine in document.TRIMLINES)
217
                        foreach (LineRun run in trimLine.RUNS)
218
                            JoinRunLine(run);
219

    
220
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount);
221
                }
222
            }
223
            catch (Exception ex)
224
            {
225
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
226
            }
227
            finally
228
            {
229
                application.ActiveWindow.Fit();
230

    
231
                if (radApp.ActiveDocument != null)
232
                {
233
                    //radApp.ActiveDocument.Save();
234
                    //radApp.ActiveDocument.SaveOnClose = false;
235
                    //radApp.ActiveDocument.Close(false);
236

    
237
                    ReleaseCOMObjects(newDrawing);
238
                }
239

    
240
                ReleaseCOMObjects(dataSource);
241
                ReleaseCOMObjects(_placement);
242

    
243
                Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document);
244
                //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
245
                SplashScreenManager.CloseForm(false);
246
            }
247
        }
248

    
249
        /// <summary>
250
        /// 도면 생성 메서드
251
        /// </summary>
252
        private void CreateDocument(ref string drawingNumber, ref string drawingName)
253
        {
254
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
255

    
256
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
257
            application.ActiveWindow.Fit();
258
            Thread.Sleep(1000);
259
            application.ActiveWindow.Zoom = 2000;
260
            Thread.Sleep(2000);
261
        }
262

    
263
        /// <summary>
264
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
265
        /// </summary>
266
        /// <param name="drawingName"></param>
267
        /// <param name="drawingNumber"></param>
268
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
269
        {
270
            LMDrawings drawings = new LMDrawings();
271
            drawings.Collect(dataSource);
272
            
273
            List<string> drawingNameList = new List<string>();
274
            List<string> drawingNumberList = new List<string>();
275

    
276
            foreach (LMDrawing item in drawings)
277
            {
278
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
279
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
280
            }
281

    
282
            int nameLength = drawingName.Length;
283
            while (drawingNameList.Contains(drawingName))
284
            {
285
                if (nameLength == drawingName.Length)
286
                    drawingName += "-1";
287
                else
288
                {
289
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
290
                    drawingName = drawingName.Substring(0, nameLength + 1);
291
                    drawingName += ++index;
292
                }
293
            }
294

    
295
            int numberLength = drawingNumber.Length;
296
            while (drawingNameList.Contains(drawingNumber))
297
            {
298
                if (numberLength == drawingNumber.Length)
299
                    drawingNumber += "-1";
300
                else
301
                {
302
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
303
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
304
                    drawingNumber += ++index;
305
                }
306
            }
307

    
308
            ReleaseCOMObjects(drawings);
309
        }
310

    
311
        /// <summary>
312
        /// 도면 크기 구하는 메서드
313
        /// </summary>
314
        /// <returns></returns>
315
        private bool DocumentCoordinateCorrection()
316
        {
317
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
318
            {
319
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
320
                document.CoordinateCorrection();
321
                return true;
322
            }
323
            else
324
                return false;
325
        }
326

    
327
        /// <summary>
328
        /// 라인을 Run 단위로 모델링하는 진입 메서드
329
        /// </summary>
330
        /// <param name="run"></param>
331
        private void LineModelingByRun(LineRun run)
332
        {
333
            Line prevLine = null;
334
            List<Line> lines = new List<Line>();
335
            foreach (var item in run.RUNITEMS)
336
            {
337
                // Line일 경우
338
                if (item.GetType() == typeof(Line))
339
                {
340
                    Line line = item as Line;
341
                    if (prevLine == null)
342
                        lines.Add(line);
343
                    else if (prevLine != null)
344
                    {
345
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
346
                            lines.Add(line);
347
                        else
348
                        {
349
                            if (lines.Count > 0)
350
                            {
351
                                LineModeling(lines);
352
                                lines.Clear();
353
                            }
354
                            lines.Add(line);
355
                        }
356
                    }
357

    
358
                    prevLine = line;
359

    
360
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
361
                }
362
                // Symbol 일 경우
363
                else if (item.GetType() == typeof(Symbol))
364
                {
365
                    if (lines.Count > 0)
366
                    {
367
                        LineModeling(lines);
368
                        lines.Clear();
369
                    }
370
                }
371
            }
372

    
373
            if (lines.Count > 0)
374
                LineModeling(lines);
375
        }
376

    
377
        /// <summary>
378
        /// 심볼을 Run 단위로 모델링하는 진입 메서드
379
        /// </summary>
380
        /// <param name="run"></param>
381
        private void SymbolModelingByRun(LineRun run)
382
        {
383
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
384
            if (run.RUNITEMS.Count > 0)
385
            {
386
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
387
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
388

    
389
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
390
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
391
            }
392

    
393
            Symbol targetSymbol = null;
394
            foreach (var item in run.RUNITEMS)
395
            {
396
                if (item.GetType() == typeof(Symbol))
397
                {
398
                    Symbol symbol = item as Symbol;
399
                    SymbolModeling(symbol, targetSymbol);
400
                    targetSymbol = symbol;
401
                }
402
                else
403
                {
404
                    targetSymbol = null;
405
                }
406
            }
407
        }
408

    
409
        /// <summary>
410
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점
411
        /// </summary>
412
        /// <param name="symbol"></param>
413
        /// <param name="run"></param>
414
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
415
        {
416
            foreach (var connector in symbol.CONNECTORS)
417
            {
418
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
419
                if (targetItem != null &&
420
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
421
                    !IsSameLineRun(symbol, targetItem))
422
                {
423
                    SymbolModeling(symbol, targetItem as Symbol);
424
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
425
                    {
426
                        object item = run.RUNITEMS[i];
427
                        if (item.GetType() == typeof(Symbol))
428
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol);
429
                        else
430
                            break;
431
                    }
432
                    break;
433
                }
434
            }
435

    
436

    
437
        }
438

    
439
        /// <summary>
440
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점
441
        /// </summary>
442
        /// <param name="symbol"></param>
443
        /// <param name="run"></param>
444
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
445
        {
446
            foreach (var connector in symbol.CONNECTORS)
447
            {
448
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
449
                if (targetItem != null &&
450
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
451
                    !IsSameLineRun(symbol, targetItem))
452
                {
453
                    SymbolModeling(symbol, targetItem as Symbol);
454
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
455
                    {
456
                        object item = run.RUNITEMS[i];
457
                        if (item.GetType() == typeof(Symbol))
458
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol);
459
                        else
460
                            break;
461
                    }
462
                    break;
463
                }
464
            }
465
        }
466

    
467
        /// <summary>
468
        /// 심볼을 실제로 Modeling 메서드
469
        /// </summary>
470
        /// <param name="symbol"></param>
471
        /// <param name="targetSymbol"></param>
472
        /// <param name="prevSymbol"></param>
473
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
474
        {
475
#if DEBUG
476
            try
477
            {
478
#endif
479
                // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
480
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
481
                if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None")
482
                    return;
483
                // 이미 모델링 됐을 경우
484
                else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
485
                    return;
486

    
487
                LMSymbol _LMSymbol = null;
488

    
489
                string mappingPath = symbol.SPPID.MAPPINGNAME;
490
                double x = symbol.SPPID.ORIGINAL_X;
491
                double y = symbol.SPPID.ORIGINAL_Y;
492
                int mirror = 0;
493
                double angle = symbol.ANGLE;
494

    
495
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
496

    
497
                // OPC 일경우 180도 일때 Mirror
498
                if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
499
                    mirror = 1;
500

    
501
                // Mirror 계산
502
                if (symbol.FLIP == 1)
503
                {
504
                    mirror = 1;
505
                    angle += Math.PI;
506
                }
507

    
508
                if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
509
                {
510
                    LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
511
                    Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
512
                    if (connector != null)
513
                        GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
514

    
515
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
516

    
517
                    if (_LMSymbol != null && _TargetItem != null)
518
                    {
519
                        symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
520
                        LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
521

    
522
                        if (reModelingConnector != null)
523
                            ReModelingLMConnector(reModelingConnector);
524
                    }
525

    
526
                    ReleaseCOMObjects(_TargetItem);
527
                }
528
                else
529
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
530

    
531

    
532
                if (_LMSymbol != null)
533
                {
534
                    _LMSymbol.Commit();
535
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
536
                    symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
537
                    symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
538

    
539
                    foreach (var item in symbol.ChildSymbols)
540
                        CreateChildSymbol(item, _LMSymbol);
541
                }
542

    
543
                ReleaseCOMObjects(_LMSymbol);
544
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
545
#if DEBUG
546

    
547
            }
548
            catch (Exception ex)
549
            {
550
                System.Windows.Forms.MessageBox.Show(ex.StackTrace);
551
            }
552
#endif
553
        }
554

    
555
        /// <summary>
556
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
557
        /// </summary>
558
        /// <param name="targetConnector"></param>
559
        /// <param name="targetSymbol"></param>
560
        /// <param name="x"></param>
561
        /// <param name="y"></param>
562
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
563
        {
564
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
565

    
566
            double[] range = null;
567
            List<double[]> points = new List<double[]>();
568
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
569
            double x1 = range[0];
570
            double y1 = range[1];
571
            double x2 = range[2];
572
            double y2 = range[3];
573

    
574
            // Origin 기준 Connector의 위치차이
575
            double sceneX = 0;
576
            double sceneY = 0;
577
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
578
            double originX = 0;
579
            double originY = 0;
580
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
581
            double gapX = originX - sceneX;
582
            double gapY = originY - sceneY;
583

    
584
            // SPPID Symbol과 ID2 심볼의 크기 차이
585
            double sizeWidth = 0;
586
            double sizeHeight = 0;
587
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
588
            double percentX = (x2 - x1) / sizeWidth;
589
            double percentY = (y2 - y1) / sizeHeight;
590

    
591
            double SPPIDgapX = gapX * percentX;
592
            double SPPIDgapY = gapY * percentY;
593

    
594
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
595
            double distance = double.MaxValue;
596
            double[] resultPoint;
597
            foreach (var point in points)
598
            {
599
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
600
                if (distance > result)
601
                {
602
                    distance = result;
603
                    resultPoint = point;
604
                    x = point[0];
605
                    y = point[1];
606
                }
607
            }
608

    
609
            ReleaseCOMObjects(_TargetItem);
610
        }
611

    
612
        /// <summary>
613
        /// SPPID Symbol의 Range를 구한다.
614
        /// </summary>
615
        /// <param name="symbol"></param>
616
        /// <param name="range"></param>
617
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
618
        {
619
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
620
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
621
            double x1 = 0;
622
            double y1 = 0;
623
            double x2 = 0;
624
            double y2 = 0;
625
            symbol2d.Range(out x1, out y1, out x2, out y2);
626
            range = new double[] { x1, y1, x2, y2 };
627

    
628
            for (int i = 1; i < int.MaxValue; i++)
629
            {
630
                double connX = 0;
631
                double connY = 0;
632
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
633
                    points.Add(new double[] { connX, connY });
634
                else
635
                    break;
636
            }
637

    
638
            foreach (var childSymbol in symbol.ChildSymbols)
639
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
640

    
641
            ReleaseCOMObjects(_TargetItem);
642
        }
643

    
644
        /// <summary>
645
        /// Child Modeling 된 Symbol의 Range를 구한다.
646
        /// </summary>
647
        /// <param name="childSymbol"></param>
648
        /// <param name="range"></param>
649
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
650
        {
651
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
652
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
653
            double x1 = 0;
654
            double y1 = 0;
655
            double x2 = 0;
656
            double y2 = 0;
657
            symbol2d.Range(out x1, out y1, out x2, out y2);
658
            range[0] = Math.Min(range[0], x1);
659
            range[1] = Math.Min(range[1], y1);
660
            range[2] = Math.Max(range[2], x2);
661
            range[3] = Math.Max(range[3], y2);
662

    
663
            for (int i = 1; i < int.MaxValue; i++)
664
            {
665
                double connX = 0;
666
                double connY = 0;
667
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
668
                    points.Add(new double[] { connX, connY });
669
                else
670
                    break;
671
            }
672

    
673
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
674
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
675

    
676
            ReleaseCOMObjects(_ChildSymbol);
677
        }
678

    
679
        /// <summary>
680
        /// Label Symbol Modeling
681
        /// </summary>
682
        /// <param name="symbol"></param>
683
        private void LabelSymbolModeling(Symbol symbol)
684
        {
685
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
686
            if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE))
687
                return;
688

    
689
            Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
690
            
691
            string symbolUID = itemAttribute.VALUE;
692
            object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
693
            if (targetItem != null && 
694
                (targetItem.GetType() == typeof(Symbol) ||
695
                targetItem.GetType() == typeof(Equipment)))
696
            {
697
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
698
                string sRep = null;
699
                if (targetItem.GetType() == typeof(Symbol))
700
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
701
                else if (targetItem.GetType() == typeof(Equipment))
702
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
703
                if (!string.IsNullOrEmpty(sRep))
704
                {
705
                    // LEADER Line 검사
706
                    bool leaderLine = false;
707
                    SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
708
                    if (symbolMapping != null)
709
                        leaderLine = symbolMapping.LEADERLINE;
710

    
711
                    // Target Symbol Item 가져오고 Label Modeling
712
                    LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
713
                    LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
714

    
715
                    //Leader 선 센터로
716
                    if (_LMLabelPresist != null)
717
                    {
718
                        // Target Item에 Label의 Attribute Input
719
                        InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
720

    
721
                        string OID = _LMLabelPresist.get_GraphicOID();
722
                        DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
723
                        if (dependency != null)
724
                        {
725
                            bool result = false;
726
                            foreach (var attributes in dependency.AttributeSets)
727
                            {
728
                                foreach (var attribute in attributes)
729
                                {
730
                                    string name = attribute.Name;
731
                                    string value = attribute.GetValue().ToString();
732
                                    if (name == "DrawingItemType" && value == "LabelPersist")
733
                                    {
734
                                        foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
735
                                        {
736
                                            if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
737
                                            {
738
                                                Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
739
                                                double prevX = _TargetItem.get_XCoordinate();
740
                                                double prevY = _TargetItem.get_YCoordinate();
741
                                                lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
742
                                                lineString2D.RemoveVertex(lineString2D.VertexCount);
743
                                                result = true;
744
                                                break;
745
                                            }
746
                                        }
747
                                    }
748

    
749
                                    if (result)
750
                                        break;
751
                                }
752

    
753
                                if (result)
754
                                    break;
755
                            }
756
                        }
757

    
758
                        _LMLabelPresist.Commit();
759
                        ReleaseCOMObjects(_LMLabelPresist);
760
                    }
761
                    
762
                    ReleaseCOMObjects(_TargetItem);
763
                }
764
            }
765
            else if (targetItem != null && targetItem.GetType() == typeof(Line))
766
            {
767
                Line targetLine = targetItem as Line;
768
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
769
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
770
                if (connectedLMConnector != null)
771
                {
772
                    // LEADER Line 검사
773
                    bool leaderLine = false;
774
                    SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
775
                    if (symbolMapping != null)
776
                        leaderLine = symbolMapping.LEADERLINE;
777

    
778
                    LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
779
                    if (_LMLabelPresist != null)
780
                    {
781
                        _LMLabelPresist.Commit();
782
                        ReleaseCOMObjects(_LMLabelPresist);
783
                    }
784
                    ReleaseCOMObjects(connectedLMConnector);
785
                }
786

    
787
                foreach (var item in connectorVertices)
788
                    if (item.Key != null)
789
                        ReleaseCOMObjects(item.Key);
790
            }
791

    
792
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
793
        }
794

    
795
        /// <summary>
796
        /// Equipment를 실제로 Modeling 메서드
797
        /// </summary>
798
        /// <param name="equipment"></param>
799
        private void EquipmentModeling(Equipment equipment)
800
        {
801
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
802
                return;
803

    
804
            LMSymbol _LMSymbol = null;
805
            LMSymbol targetItem = null;
806
            string mappingPath = equipment.SPPID.MAPPINGNAME;
807
            double x = equipment.SPPID.ORIGINAL_X;
808
            double y = equipment.SPPID.ORIGINAL_Y;
809
            int mirror = 0;
810
            double angle = equipment.ANGLE;
811

    
812
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
813

    
814
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
815
            if (connector != null)
816
            {
817
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
818
                if (connEquipment != null)
819
                {
820
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
821
                        EquipmentModeling(connEquipment);
822

    
823
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
824
                    {
825
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
826
                        if (targetItem != null)
827
                        {
828
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
829
                        }
830
                        else
831
                        {
832
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
833
                        }
834
                    }
835
                    else
836
                    {
837
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
838
                    }
839
                }
840
                else
841
                {
842
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
843
                }
844
            }
845
            else
846
            {
847
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
848
            }
849

    
850
            if (_LMSymbol != null)
851
            {
852
                _LMSymbol.Commit();
853
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
854
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
855
                ReleaseCOMObjects(_LMSymbol);
856
            }
857

    
858
            if (targetItem != null)
859
            {
860
                ReleaseCOMObjects(targetItem);
861
            }
862
            
863
            ReleaseCOMObjects(_LMSymbol);
864

    
865
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
866
        }
867

    
868
        private void SymbolModelingByPriority(Symbol symbol)
869
        {
870
            // Angle, Center, 우선순위 모델링
871
            SymbolModeling(symbol, null);
872
            List<Symbol> group = new List<Symbol>() { symbol };
873
            SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group);
874

    
875
            List<Symbol> endModeling = new List<Symbol>() { symbol };
876
            while (endModeling.Count != group.Count)
877
            {
878
                foreach (var item in group)
879
                {
880
                    if (!endModeling.Contains(item))
881
                    {
882
                        bool result = false;
883
                        foreach (var connector in item.CONNECTORS)
884
                        {
885
                            Symbol connSymbol = group.Find(x => x.UID == connector.CONNECTEDITEM);
886
                            if (connSymbol == item)
887
                                throw new Exception(connSymbol.UID);
888

    
889
                            if (connSymbol != null && endModeling.Contains(connSymbol))
890
                            {
891
                                SymbolModeling(item, connSymbol);
892
                                endModeling.Add(item);
893
                                result = true;
894
                                break;
895
                            }
896
                        }
897

    
898
                        if (result)
899
                            break;
900
                    }
901
                }
902
            }
903
        }
904

    
905
        /// <summary>
906
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
907
        /// </summary>
908
        /// <param name="childSymbol"></param>
909
        /// <param name="parentSymbol"></param>
910
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
911
        {
912
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
913
            double x1 = 0;
914
            double x2 = 0;
915
            double y1 = 0;
916
            double y2 = 0;
917
            symbol2d.Range(out x1, out y1, out x2, out y2);
918

    
919
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
920
            if (_LMSymbol != null)
921
            {
922
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
923
                foreach (var item in childSymbol.ChildSymbols)
924
                    CreateChildSymbol(item, _LMSymbol);
925
            }
926
            
927

    
928
            ReleaseCOMObjects(_LMSymbol);
929
        }
930

    
931
        /// <summary>
932
        /// item이 TargetItem과 같은 LineRun에 있는지 검사
933
        /// </summary>
934
        /// <param name="item"></param>
935
        /// <param name="targetItem"></param>
936
        /// <returns></returns>
937
        private bool IsSameLineRun(object item, object targetItem)
938
        {
939
            foreach (var lineNumber in document.LINENUMBERS)
940
            {
941
                foreach (var run in lineNumber.RUNS)
942
                {
943
                    foreach (var runItem in run.RUNITEMS)
944
                    {
945
                        if (runItem == item)
946
                        {
947
                            foreach (var findItem in run.RUNITEMS)
948
                            {
949
                                if (findItem == targetItem)
950
                                {
951
                                    return true;
952
                                }
953
                            }
954

    
955
                            return false;
956

    
957
                        }
958
                    }
959
                }
960
            }
961

    
962
            return false;
963
        }
964

    
965
        /// <summary>
966
        /// Line을 실제로 모델링하는 메서드
967
        /// </summary>
968
        /// <param name="lines"></param>
969
        private void LineModeling(List<Line> lines)
970
        {
971
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
972
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
973
            LMSymbol _LMSymbol1 = null;
974
            LMSymbol _LMSymbol2 = null;
975
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
976
            LMConnector targetConnector1 = null;
977
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
978
            LMConnector targetConnector2 = null;
979
            
980
            Line startBranchLine = null;
981
            Line endBranchLine = null;
982

    
983
            // Type, Line, TargetObjet, x, y
984
            List<Tuple<string, Line, object, double, double>> linePointInfo = new List<Tuple<string, Line, object, double, double>>();
985
            // Point 정리
986
            for (int i = 0; i < lines.Count; i++)
987
            {
988
                Line line = lines[i];
989
                if (i == 0 || i + 1 != lines.Count)
990
                {
991
                    // 시작점에 연결된 Symbol 찾기
992
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
993
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
994
                    {
995
                        Symbol symbol1 = connItem as Symbol;
996
                        _LMSymbol1 = GetTargetSymbol(symbol1, line);
997
                        if (_LMSymbol1 != null)
998
                        {
999
                            double x = line.SPPID.START_X;
1000
                            double y = line.SPPID.START_Y;
1001
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1);
1002
                            if (connector != null)
1003
                            {
1004
                                GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y);
1005
                                line.SPPID.START_X = x;
1006
                                line.SPPID.START_Y = y;
1007
                            }
1008

    
1009
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol1, x, y));
1010
                        }
1011
                        else
1012
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1013
                    }
1014
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
1015
                    {
1016
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
1017
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
1018

    
1019
                        if (targetConnector1 != null)
1020
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector1, line.SPPID.START_X, line.SPPID.START_Y));
1021
                        else
1022
                        {
1023
                            startBranchLine = connItem as Line;
1024
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1025
                        }
1026
                    }
1027
                    else
1028
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1029
                        
1030
                }
1031
                if (i + 1 == lines.Count)
1032
                {
1033
                    // 끝점에 연결된 Symbol 찾기
1034
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
1035

    
1036
                    if (i != 0)
1037
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1038

    
1039
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
1040
                    {
1041
                        Symbol symbol2 = connItem as Symbol;
1042
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
1043
                        if (_LMSymbol2 != null)
1044
                        {
1045
                            double x = line.SPPID.END_X;
1046
                            double y = line.SPPID.END_Y;
1047
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2);
1048
                            if (connector != null)
1049
                            {
1050
                                GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y);
1051
                                line.SPPID.END_X = x;
1052
                                line.SPPID.END_Y = y;
1053
                            }
1054

    
1055
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol2, x, y));
1056
                        }
1057
                        else
1058
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1059
                    }
1060
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
1061
                    {
1062
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
1063
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
1064

    
1065
                        if (targetConnector2 != null)
1066
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector2, line.SPPID.END_X, line.SPPID.END_Y));
1067
                        else
1068
                        {
1069
                            endBranchLine = connItem as Line;
1070
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1071
                        }
1072
                    }
1073
                    else
1074
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1075
                }
1076
            }
1077

    
1078
            double prevX = double.NaN;
1079
            double prevY = double.NaN;
1080
            SlopeType prevSlopeType = SlopeType.None;
1081
            for (int i = 0; i < linePointInfo.Count; i++)
1082
            {
1083
                Tuple<string, Line, object, double, double> item = linePointInfo[i];
1084
                Line line = item.Item2;
1085
                double x = item.Item4;
1086
                double y = item.Item5;
1087
                SlopeType slopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
1088
                // Symbol일 경우 바로 Input Point
1089
                if (item.Item1 == "SYMBOL")
1090
                    placeRunInputs.AddSymbolTarget(item.Item3 as LMSymbol, x, y);
1091
                else
1092
                {
1093
                    SPPIDUtil.ConvertGridPoint(ref x, ref y);
1094
                    // i == 0은 그대로 사용
1095
                    if (i != 0)
1096
                    {
1097
                        Tuple<string, Line, object, double, double> prevItem = linePointInfo[i - 1];
1098
                        // y 좌표가 같아야함 및 Symbol 좌표가 정확하지 않으므로 한번더 보정
1099
                        if (prevSlopeType == SlopeType.HORIZONTAL)
1100
                        {
1101
                            y = prevY;
1102
                            SPPIDUtil.ConvertGridPointOnlyOnePoint(ref y);
1103
                        }
1104
                        else if (prevSlopeType == SlopeType.VERTICAL)
1105
                        {
1106
                            x = prevX;
1107
                            SPPIDUtil.ConvertGridPointOnlyOnePoint(ref x);
1108
                        }
1109

    
1110
                        // 마지막이 Symbol일 경우는 Symbol의 좌표를 따라감
1111
                        if (i + 1 == linePointInfo.Count - 1 && linePointInfo[i + 1].Item1 == "SYMBOL")
1112
                        {
1113
                            Line nextLine = linePointInfo[i + 1].Item2;
1114
                            SlopeType nextSlopeType = SPPIDUtil.CalcSlope(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y);
1115
                            if (slopeType == SlopeType.HORIZONTAL)
1116
                                y = linePointInfo[i + 1].Item5;
1117
                            else if (slopeType == SlopeType.VERTICAL)
1118
                                x = linePointInfo[i + 1].Item4;
1119
                        }
1120
                    }
1121

    
1122
                    if (item.Item1 == "LINE")
1123
                        placeRunInputs.AddConnectorTarget(item.Item3 as LMConnector, x, y);
1124
                    else
1125
                        placeRunInputs.AddPoint(x, y);
1126
                }
1127

    
1128
                prevX = x;
1129
                prevY = y;
1130
                prevSlopeType = slopeType;
1131
            }
1132

    
1133
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1134

    
1135
            if (_lMConnector != null)
1136
            {
1137
                if (lines.Find(x => x.UID == "d4bea462-44cc-473d-8fe2-fb2e98009578") != null)
1138
                {
1139

    
1140
                }
1141
                bool bStart = false;
1142
                bool bEnd = false;
1143

    
1144
                NeedReModeling(lines[0], _LMSymbol1, ref bStart);
1145
                NeedReModeling(lines[lines.Count - 1], _LMSymbol2, ref bEnd);
1146

    
1147
                if (bStart || bEnd)
1148
                    ReModelingLine(lines, _lMConnector, _LMSymbol1, _LMSymbol2, bStart, bEnd);
1149
                else
1150
                {
1151
                    foreach (var line in lines)
1152
                        line.SPPID.ModelItemId = _lMConnector.ModelItemID;
1153
                    _lMConnector.Commit();
1154
                }
1155

    
1156
                if (startBranchLine != null || endBranchLine != null)
1157
                    BranchLines.Add(new Tuple<string, Line, Line>(lines[0].SPPID.ModelItemId, startBranchLine, endBranchLine));
1158
            }
1159

    
1160
            if (_LMSymbol1 != null)
1161
                ReleaseCOMObjects(_LMSymbol1);
1162
            if (_LMSymbol2 != null)
1163
                ReleaseCOMObjects(_LMSymbol2);
1164
            if (targetConnector1 != null)
1165
                ReleaseCOMObjects(targetConnector1);
1166
            if (targetConnector2 != null)
1167
                ReleaseCOMObjects(targetConnector2);
1168
            foreach (var item in connectorVertices1)
1169
                ReleaseCOMObjects(item.Key);
1170
            foreach (var item in connectorVertices2)
1171
                ReleaseCOMObjects(item.Key);
1172

    
1173
            ReleaseCOMObjects(_lMConnector);
1174
            ReleaseCOMObjects(placeRunInputs);
1175
            ReleaseCOMObjects(_LMAItem);
1176
        }
1177

    
1178
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1179
        {
1180
            if (symbol != null)
1181
            {
1182
                try
1183
                {
1184
                    string repID = symbol.AsLMRepresentation().Id;
1185
                    string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1186
                    string lineUID = line.UID;
1187

    
1188
                    SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1189
                    (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1190
                    (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1191

    
1192
                    EndBreak startEndBreak = document.EndBreaks.Find(x =>
1193
                    (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1194
                    (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1195

    
1196
                    if (startSpecBreak != null || startEndBreak != null)
1197
                        result = true;
1198
                }
1199
                catch (Exception ex)
1200
                {
1201

    
1202
                }
1203
            }
1204
        }
1205
        
1206
        /// <summary>
1207
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1208
        /// </summary>
1209
        /// <param name="lines"></param>
1210
        /// <param name="prevLMConnector"></param>
1211
        /// <param name="startSymbol"></param>
1212
        /// <param name="endSymbol"></param>
1213
        private void ReModelingLine(List<Line> lines, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1214
        {
1215
            
1216
            string symbolPath = string.Empty;
1217
            #region get symbol path
1218
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1219
            foreach (LMRepresentation rep in modelItem.Representations)
1220
            {
1221
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1222
                {
1223
                    symbolPath = rep.get_FileName();
1224
                    break;
1225
                }
1226
            }
1227
            #endregion
1228
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1229
            LMConnector newConnector = null;
1230
            dynamic OID = prevLMConnector.get_GraphicOID();
1231
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1232
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1233
            int verticesCount = lineStringGeometry.VertexCount;
1234
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1235
            
1236
            List<double[]> vertices = new List<double[]>();
1237
            for (int i = 1; i <= verticesCount; i++)
1238
            {
1239
                double x = 0;
1240
                double y = 0;
1241
                lineStringGeometry.GetVertex(i, ref x, ref y);
1242
                vertices.Add(new double[] { x, y });
1243
            }
1244

    
1245
            for (int i = 0; i < vertices.Count; i++)
1246
            {
1247
                double[] points = vertices[i];
1248
                // 시작 심볼이 있고 첫번째 좌표일 때
1249
                if (startSymbol != null && i == 0)
1250
                {
1251
                    if (bStart)
1252
                    {
1253
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1254
                        if (slopeType == SlopeType.HORIZONTAL)
1255
                            placeRunInputs.AddPoint(points[0], -0.1);
1256
                        else if (slopeType == SlopeType.VERTICAL)
1257
                            placeRunInputs.AddPoint(-0.1, points[1]);
1258
                        else
1259
                            placeRunInputs.AddPoint(points[0], -0.1);
1260

    
1261
                        placeRunInputs.AddPoint(points[0], points[1]);
1262
                    }
1263
                    else
1264
                    {
1265
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1]);
1266
                    }
1267
                }
1268
                // 마지막 심볼이 있고 마지막 좌표일 때
1269
                else if (endSymbol != null && i == vertices.Count - 1)
1270
                {
1271
                    if (bEnd)
1272
                    {
1273
                        placeRunInputs.AddPoint(points[0], points[1]);
1274

    
1275
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1276
                        if (slopeType == SlopeType.HORIZONTAL)
1277
                            placeRunInputs.AddPoint(points[0], -0.1);
1278
                        else if (slopeType == SlopeType.VERTICAL)
1279
                            placeRunInputs.AddPoint(-0.1, points[1]);
1280
                        else
1281
                            placeRunInputs.AddPoint(points[0], -0.1);
1282
                    }
1283
                    else
1284
                    {
1285
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1]);
1286
                    }
1287
                }
1288
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1289
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1290
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1291
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1292
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1293
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1294
                else
1295
                    placeRunInputs.AddPoint(points[0], points[1]);
1296
            }
1297

    
1298
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1299
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1300

    
1301
            ReleaseCOMObjects(placeRunInputs);
1302
            ReleaseCOMObjects(_LMAItem);
1303
            ReleaseCOMObjects(modelItem);
1304

    
1305
            if (newConnector != null)
1306
            {
1307
                if (startSymbol != null && bStart)
1308
                {
1309
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1310
                    placeRunInputs = new PlaceRunInputs();
1311
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1312
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1313
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1314
                    if (_LMConnector != null)
1315
                    {
1316
                        RemoveConnectorForReModelingLine(newConnector);
1317
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1318
                        ReleaseCOMObjects(_LMConnector);
1319
                    }
1320
                    ReleaseCOMObjects(placeRunInputs);
1321
                    ReleaseCOMObjects(_LMAItem);
1322
                }
1323

    
1324
                if (endSymbol != null && bEnd)
1325
                {
1326
                    if (startSymbol != null)
1327
                    {
1328
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1329
                        newConnector = dicVertices.First().Key;
1330
                    }
1331

    
1332
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1333
                    placeRunInputs = new PlaceRunInputs();
1334
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1335
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1336
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1337
                    if (_LMConnector != null)
1338
                    {
1339
                        RemoveConnectorForReModelingLine(newConnector);
1340
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1341
                        ReleaseCOMObjects(_LMConnector);
1342
                    }
1343
                    ReleaseCOMObjects(placeRunInputs);
1344
                    ReleaseCOMObjects(_LMAItem);
1345
                }
1346

    
1347
                foreach (var line in lines)
1348
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
1349
                ReleaseCOMObjects(newConnector);
1350
            }
1351

    
1352
            ReleaseCOMObjects(modelItem);
1353
        }
1354

    
1355
        /// <summary>
1356
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
1357
        /// </summary>
1358
        /// <param name="connector"></param>
1359
        private void RemoveConnectorForReModelingLine(LMConnector connector)
1360
        {
1361
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
1362
            foreach (var item in dicVertices)
1363
            {
1364
                bool result = false;
1365
                foreach (var point in item.Value)
1366
                {
1367
                    if (point[0] < 0 || point[1] < 0)
1368
                    {
1369
                        result = true;
1370
                        _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
1371
                        break;
1372
                    }
1373
                }
1374

    
1375
                if (result)
1376
                    break;
1377
            }
1378
            foreach (var item in dicVertices)
1379
                ReleaseCOMObjects(item.Key);
1380
        }
1381

    
1382
        /// <summary>
1383
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
1384
        /// </summary>
1385
        /// <param name="symbol"></param>
1386
        /// <param name="line"></param>
1387
        /// <returns></returns>
1388
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
1389
        {
1390
            LMSymbol _LMSymbol = null;
1391
            foreach (var connector in symbol.CONNECTORS)
1392
            {
1393
                if (connector.CONNECTEDITEM == line.UID)
1394
                {
1395
                    if (connector.Index == 0)
1396
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1397
                    else
1398
                    {
1399
                        ChildSymbol child = null;
1400
                        foreach (var childSymbol in symbol.ChildSymbols)
1401
                        {
1402
                            if (childSymbol.Connectors.Contains(connector))
1403
                                child = childSymbol;
1404
                            else
1405
                                child = GetChildSymbolByConnector(childSymbol, connector);
1406

    
1407
                            if (child != null)
1408
                                break;
1409
                        }
1410

    
1411
                        if (child != null)
1412
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
1413
                    }
1414

    
1415
                    break;  
1416
                }
1417
            }
1418

    
1419
            return _LMSymbol;
1420
        }
1421

    
1422
        /// <summary>
1423
        /// Connector를 가지고 있는 ChildSymbol Object 반환
1424
        /// </summary>
1425
        /// <param name="item"></param>
1426
        /// <param name="connector"></param>
1427
        /// <returns></returns>
1428
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
1429
        {
1430
            foreach (var childSymbol in item.ChildSymbols)
1431
            {
1432
                if (childSymbol.Connectors.Contains(connector))
1433
                    return childSymbol;
1434
                else
1435
                    return GetChildSymbolByConnector(childSymbol, connector);
1436
            }
1437

    
1438
            return null;
1439
        }
1440

    
1441
        /// <summary>
1442
        /// Branch 라인을 다시 모델링하는 진입 메서드
1443
        /// </summary>
1444
        /// <param name="branch"></param>
1445
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
1446
        {
1447
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1448

    
1449
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1450
            LMConnector _StartConnector = null;
1451
            LMConnector _EndConnector = null;
1452
            double lengthStart = double.MaxValue;
1453
            double lengthEnd = double.MaxValue;
1454
            List<double[]> startPoints = new List<double[]>();
1455
            List<double[]> endPoints = new List<double[]>();
1456

    
1457
            foreach (var item in connectorVertices)
1458
            {
1459
                foreach (var point in item.Value)
1460
                {
1461
                    // Start Point가 Branch
1462
                    if (branch.Item2 != null)
1463
                    {
1464
                        Line targetLine = branch.Item2;
1465
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1466
                        if (lengthStart > distance)
1467
                        {
1468
                            _StartConnector = item.Key;
1469
                            lengthStart = distance;
1470
                            startPoints = item.Value;
1471
                        }
1472
                    }
1473
                    // End Point가 Branch
1474
                    if (branch.Item3 != null)
1475
                    {
1476
                        Line targetLine = branch.Item3;
1477
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1478
                        if (lengthEnd > distance)
1479
                        {
1480
                            _EndConnector = item.Key;
1481
                            lengthEnd = distance;
1482
                            endPoints = item.Value;
1483
                        }
1484
                    }
1485
                }
1486
            }
1487
            #region Branch가 양쪽 전부일 때
1488
            if (_StartConnector != null && _StartConnector == _EndConnector)
1489
            {
1490
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
1491

    
1492
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1493
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1494

    
1495
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1496
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
1497
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1498
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
1499
                   startPoints[startPoints.Count - 1][0],
1500
                   startPoints[startPoints.Count - 1][1],
1501
                   startPoints[startPoints.Count - 2][0],
1502
                   startPoints[startPoints.Count - 2][1]);
1503

    
1504
                for (int i = 0; i < startPoints.Count; i++)
1505
                {
1506
                    double[] point = startPoints[i];
1507
                    if (i == 0)
1508
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
1509
                    else if (i == startPoints.Count - 1)
1510
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
1511
                    else
1512
                        placeRunInputs.AddPoint(point[0], point[1]);
1513
                }
1514

    
1515
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1516
                if (_LMConnector != null)
1517
                {
1518
                    _LMConnector.Commit();
1519
                    foreach (var item in lines)
1520
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1521
                }
1522

    
1523
                foreach (var item in startConnectorVertices)
1524
                    ReleaseCOMObjects(item.Key);
1525
                foreach (var item in endConnectorVertices)
1526
                    ReleaseCOMObjects(item.Key);
1527
                ReleaseCOMObjects(placeRunInputs);
1528
                ReleaseCOMObjects(_LMAItem);
1529
                ReleaseCOMObjects(_LMConnector);
1530
            }
1531
            #endregion
1532
            #region 양쪽이 다른 Branch 
1533
            else
1534
            {
1535
                // Branch 시작 Connector
1536
                if (_StartConnector != null)
1537
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
1538
                // Branch 끝 Connector
1539
                else if (_EndConnector != null)
1540
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
1541
            }
1542
            #endregion
1543

    
1544
            if (_StartConnector != null)
1545
                ReleaseCOMObjects(_StartConnector);
1546
            if (_EndConnector != null)
1547
                ReleaseCOMObjects(_EndConnector);
1548
            foreach (var item in connectorVertices)
1549
                ReleaseCOMObjects(item.Key);
1550
        }
1551

    
1552
        /// <summary>
1553
        /// Branch 라인을 다시 실제로 모델링하는 메서드
1554
        /// </summary>
1555
        /// <param name="branch"></param>
1556
        /// <param name="_Connector"></param>
1557
        /// <param name="points"></param>
1558
        /// <param name="IsStart"></param>
1559
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
1560
        {
1561
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1562
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1563
            LMConnector _SameRunTargetConnector = null;
1564
            LMSymbol _SameRunTargetLMSymbol = null;
1565
            Symbol _SameRunTargetSymbol = null;
1566
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
1567
            LMConnector _BranchTargetConnector = null;
1568
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1569

    
1570
            // 같은 Line Run의 Connector 찾기
1571
            foreach (var item in connectorVertices)
1572
            {
1573
                if (item.Key == _Connector)
1574
                    continue;
1575

    
1576
                if (IsStart &&
1577
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
1578
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
1579
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
1580
                {
1581
                    _SameRunTargetConnector = item.Key;
1582
                    break;
1583
                }
1584
                else if (!IsStart &&
1585
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
1586
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
1587
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
1588
                {
1589
                    _SameRunTargetConnector = item.Key;
1590
                    break;
1591
                }
1592
            }
1593

    
1594
            // Branch 반대편이 Symbol
1595
            if (_SameRunTargetConnector == null)
1596
            {
1597
                foreach (var line in lines)
1598
                {
1599
                    foreach (var connector in line.CONNECTORS)
1600
                    {
1601
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
1602
                        if (symbol != null)
1603
                        {
1604
                            _SameRunTargetSymbol = symbol;
1605
                            _SameRunTargetLMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1606
                            break;
1607
                        }
1608
                    }
1609
                }
1610
            }
1611

    
1612
            // 기존 Connector 제거
1613
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
1614
            
1615
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
1616
            if (IsStart)
1617
            {
1618
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1619
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
1620
            }
1621
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
1622
            else
1623
            {
1624
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1625
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
1626
                    points[points.Count - 1][0],
1627
                    points[points.Count - 1][1],
1628
                    points[points.Count - 2][0],
1629
                    points[points.Count - 2][1]);
1630
            }
1631

    
1632

    
1633
            bool bNeedRemodeling = false;
1634
            if (_SameRunTargetLMSymbol != null)
1635
            {
1636
                Line line = lines.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == _SameRunTargetSymbol.UID) != null);
1637
                NeedReModeling(line, _SameRunTargetLMSymbol, ref bNeedRemodeling);
1638
            }
1639

    
1640

    
1641

    
1642
            for (int i = 0; i < points.Count; i++)
1643
            {
1644
                double[] point = points[i];
1645
                if (i == 0)
1646
                {
1647
                    if (IsStart)
1648
                    {
1649
                        if (_BranchTargetConnector != null)
1650
                        {
1651
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1652
                        }
1653
                        else
1654
                        {
1655
                            placeRunInputs.AddPoint(point[0], point[1]);
1656
                        }
1657
                    }
1658
                    else
1659
                    {
1660
                        if (_SameRunTargetConnector != null)
1661
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1662
                        else if (_SameRunTargetLMSymbol != null && bNeedRemodeling)
1663
                        {
1664
                            SlopeType slopeType = SPPIDUtil.CalcSlope(point[0], point[1], points[i + 1][0], points[i + 1][1]);
1665
                            if (slopeType == SlopeType.HORIZONTAL)
1666
                                placeRunInputs.AddPoint(point[0], -0.1);
1667
                            else if (slopeType == SlopeType.VERTICAL)
1668
                                placeRunInputs.AddPoint(-0.1, point[1]);
1669
                            else
1670
                                placeRunInputs.AddPoint(point[0], -0.1);
1671

    
1672
                            placeRunInputs.AddPoint(point[0], point[1]);
1673
                        }
1674
                        else if (_SameRunTargetLMSymbol != null)
1675
                            placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]);
1676
                        else
1677
                            placeRunInputs.AddPoint(point[0], point[1]);
1678
                    }
1679
                }
1680
                else if (i == points.Count - 1)
1681
                {
1682
                    if (IsStart)
1683
                    {
1684
                        if (_SameRunTargetConnector != null)
1685
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1686
                        else if (_SameRunTargetLMSymbol != null && bNeedRemodeling)
1687
                        {
1688
                            placeRunInputs.AddPoint(point[0], point[1]);
1689

    
1690
                            SlopeType slopeType = SPPIDUtil.CalcSlope(point[0], point[1], points[i - 1][0], points[i - 1][1]);
1691
                            if (slopeType == SlopeType.HORIZONTAL)
1692
                                placeRunInputs.AddPoint(point[0], -0.1);
1693
                            else if (slopeType == SlopeType.VERTICAL)
1694
                                placeRunInputs.AddPoint(-0.1, point[1]);
1695
                            else
1696
                                placeRunInputs.AddPoint(point[0], -0.1);
1697
                        }
1698
                        else if (_SameRunTargetLMSymbol != null)
1699
                            placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]);
1700
                        else
1701
                            placeRunInputs.AddPoint(point[0], point[1]);
1702
                    }
1703
                    else
1704
                    {
1705
                        if (_BranchTargetConnector != null)
1706
                        {
1707
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1708
                        }
1709
                        else
1710
                        {
1711
                            placeRunInputs.AddPoint(point[0], point[1]);
1712
                        }
1713
                    }
1714
                }
1715
                else
1716
                    placeRunInputs.AddPoint(point[0], point[1]);
1717
            }
1718
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1719
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1720

    
1721
            if (_LMConnector != null)
1722
            {
1723
                if (_SameRunTargetConnector != null)
1724
                {
1725
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
1726
                }
1727
                else
1728
                {
1729
                    if (_SameRunTargetLMSymbol != null && bNeedRemodeling)
1730
                    {
1731
                        string symbolPath = string.Empty;
1732
                        #region get symbol path
1733
                        LMModelItem modelItem = dataSource.GetModelItem(_LMConnector.ModelItemID);
1734
                        foreach (LMRepresentation rep in modelItem.Representations)
1735
                        {
1736
                            if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1737
                            {
1738
                                symbolPath = rep.get_FileName();
1739
                                break;
1740
                            }
1741
                        }
1742
                        ReleaseCOMObjects(modelItem);
1743
                        #endregion
1744

    
1745
                        double[] point = null;
1746
                        if (IsStart)
1747
                            point = points[points.Count - 1];
1748
                        else
1749
                            point = points[0];
1750

    
1751
                        _LMAItem = _placement.PIDCreateItem(symbolPath);
1752
                        placeRunInputs = new PlaceRunInputs();
1753
                        placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]);
1754
                        placeRunInputs.AddConnectorTarget(_LMConnector, point[0], point[1]);
1755
                        LMConnector _ZeroLengthLMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1756
                        if (_ZeroLengthLMConnector != null)
1757
                        {
1758
                            RemoveConnectorForReModelingLine(_LMConnector);
1759
                            ZeroLengthModelItemID.Add(_ZeroLengthLMConnector.ModelItemID);
1760
                            ReleaseCOMObjects(_ZeroLengthLMConnector);
1761
                        }
1762
                        ReleaseCOMObjects(placeRunInputs);
1763
                        ReleaseCOMObjects(_LMAItem);
1764
                    }
1765

    
1766
                    foreach (var item in lines)
1767
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1768
                }
1769

    
1770
                _LMConnector.Commit();
1771
                ReleaseCOMObjects(_LMConnector);
1772
            }
1773

    
1774
            ReleaseCOMObjects(placeRunInputs);
1775
            ReleaseCOMObjects(_LMAItem);
1776
            if (_BranchTargetConnector != null)
1777
                ReleaseCOMObjects(_BranchTargetConnector);
1778
            if (_SameRunTargetConnector != null)
1779
                ReleaseCOMObjects(_SameRunTargetConnector);
1780
            if (_SameRunTargetLMSymbol != null)
1781
                ReleaseCOMObjects(_SameRunTargetLMSymbol);
1782
            foreach (var item in connectorVertices)
1783
                ReleaseCOMObjects(item.Key);
1784
            foreach (var item in branchConnectorVertices)
1785
                ReleaseCOMObjects(item.Key);
1786
        }
1787

    
1788
        /// <summary>
1789
        /// EndBreak 모델링 메서드
1790
        /// </summary>
1791
        /// <param name="endBreak"></param>
1792
        private void EndBreakModeling(EndBreak endBreak)
1793
        {
1794
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
1795
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
1796
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
1797

    
1798
            if (targetLMConnector != null)
1799
            {
1800
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1801
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1802
            }
1803
            
1804
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1805
        }
1806

    
1807
        private LMConnector ReModelingLMConnector(LMConnector connector)
1808
        {
1809
            string symbolPath = string.Empty;
1810
            #region get symbol path
1811
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
1812
            foreach (LMRepresentation rep in modelItem.Representations)
1813
            {
1814
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1815
                {
1816
                    symbolPath = rep.get_FileName();
1817
                    break;
1818
                }
1819
            }
1820
            #endregion
1821

    
1822
            LMConnector newConnector = null;
1823
            dynamic OID = connector.get_GraphicOID();
1824
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1825
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1826
            int verticesCount = lineStringGeometry.VertexCount;
1827
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1828
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1829

    
1830
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
1831
            {
1832
                double[] vertices = null;
1833
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1834
                double x = 0;
1835
                double y = 0;
1836
                lineStringGeometry.GetVertex(1, ref x, ref y);
1837

    
1838
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
1839
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
1840

    
1841
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
1842
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1843
            }
1844
            else
1845
            {
1846
                List<double[]> vertices = new List<double[]>();
1847
                for (int i = 1; i <= verticesCount; i++)
1848
                {
1849
                    double x = 0;
1850
                    double y = 0;
1851
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1852
                    vertices.Add(new double[] { x, y });
1853
                }
1854

    
1855
                for (int i = 0; i < vertices.Count; i++)
1856
                {
1857
                    double[] points = vertices[i];
1858
                    if (i == 0)
1859
                    {
1860
                        if (connector.ConnectItem1SymbolObject != null)
1861
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
1862
                        else
1863
                            placeRunInputs.AddPoint(points[0], points[1]);
1864
                    }
1865
                    else if (i == vertices.Count - 1)
1866
                    {
1867
                        if (connector.ConnectItem2SymbolObject != null)
1868
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
1869
                        else
1870
                            placeRunInputs.AddPoint(points[0], points[1]);
1871
                    }
1872
                    else
1873
                        placeRunInputs.AddPoint(points[0], points[1]);
1874
                }
1875

    
1876
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID);
1877

    
1878
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
1879
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1880

    
1881
                foreach (var line in lines)
1882
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
1883
            }
1884

    
1885

    
1886
            return newConnector;
1887
        }
1888

    
1889
        /// <summary>
1890
        /// SpecBreak Modeling 메서드
1891
        /// </summary>
1892
        /// <param name="specBreak"></param>
1893
        private void SpecBreakModeling(SpecBreak specBreak)
1894
        {
1895
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
1896
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
1897

    
1898
            if (upStreamObj != null &&
1899
                downStreamObj != null)
1900
            {
1901
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
1902

    
1903
                if (targetLMConnector != null)
1904
                {
1905
                    foreach (var attribute in specBreak.ATTRIBUTES)
1906
                    {
1907
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
1908
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
1909
                        {
1910
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
1911
                            Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
1912
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
1913

    
1914
                            if (_LmLabelPersist != null)
1915
                            {
1916
                                ReleaseCOMObjects(_LmLabelPersist);
1917
                            }
1918
                        }
1919
                    }
1920
                    ReleaseCOMObjects(targetLMConnector);
1921
                }
1922
            }
1923
        }
1924

    
1925
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
1926
        {
1927
            LMConnector targetConnector = null;
1928
            Symbol targetSymbol = targetObj as Symbol;
1929
            Symbol connectedSymbol = connectedObj as Symbol;
1930
            Line targetLine = targetObj as Line;
1931
            Line connectedLine = connectedObj as Line;
1932
            if (targetSymbol != null && connectedSymbol != null)
1933
            {
1934
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
1935
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
1936

    
1937
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
1938
                {
1939
                    if (connector.get_ItemStatus() != "Active")
1940
                        continue;
1941

    
1942
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
1943
                    {
1944
                        targetConnector = connector;
1945
                        break;
1946
                    }
1947
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
1948
                    {
1949
                        targetConnector = connector;
1950
                        break;
1951
                    }
1952
                }
1953

    
1954
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
1955
                {
1956
                    if (connector.get_ItemStatus() != "Active")
1957
                        continue;
1958

    
1959
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
1960
                    {
1961
                        targetConnector = connector;
1962
                        break;
1963
                    }
1964
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
1965
                    {
1966
                        targetConnector = connector;
1967
                        break;
1968
                    }
1969
                }
1970

    
1971
                ReleaseCOMObjects(targetLMSymbol);
1972
                ReleaseCOMObjects(connectedLMSymbol);
1973
            }
1974
            else if (targetLine != null && connectedLine != null)
1975
            {
1976
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
1977
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
1978

    
1979
                if (targetModelItem != null && connectedModelItem != null)
1980
                {
1981
                    foreach (LMRepresentation rep in targetModelItem.Representations)
1982
                    {
1983
                        if (targetConnector != null)
1984
                            break;
1985

    
1986
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1987
                        {
1988
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1989

    
1990
                            if (IsConnected(_LMConnector, connectedModelItem))
1991
                                targetConnector = _LMConnector;
1992
                            else
1993
                                ReleaseCOMObjects(_LMConnector);
1994
                        }
1995
                    }
1996

    
1997
                    ReleaseCOMObjects(targetModelItem);
1998
                }
1999
            }
2000
            else
2001
            {
2002
                LMSymbol connectedLMSymbol = connectedSymbol != null ? 
2003
                    dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId) : dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2004
                LMModelItem targetModelItem = targetLine != null ?
2005
                    dataSource.GetModelItem(targetLine.SPPID.ModelItemId) : dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2006
                if (connectedLMSymbol != null && targetModelItem != null)
2007
                {
2008
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2009
                    {
2010
                        if (connector.get_ItemStatus() != "Active")
2011
                            continue;
2012

    
2013
                        if (IsConnected(connector, targetModelItem))
2014
                        {
2015
                            targetConnector = connector;
2016
                            break;
2017
                        }
2018
                    }
2019

    
2020
                    if (targetConnector == null)
2021
                    {
2022
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2023
                        {
2024
                            if (connector.get_ItemStatus() != "Active")
2025
                                continue;
2026

    
2027
                            if (IsConnected(connector, targetModelItem))
2028
                            {
2029
                                targetConnector = connector;
2030
                                break;
2031
                            }
2032
                        }
2033
                    }
2034
                }
2035

    
2036
            }
2037

    
2038
            return targetConnector;
2039
        }
2040

    
2041
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2042
        {
2043
            bool result = false;
2044

    
2045
            foreach (LMRepresentation rep in modelItem.Representations)
2046
            {
2047
                if (result)
2048
                    break;
2049

    
2050
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2051
                {
2052
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2053

    
2054
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2055
                        connector.ConnectItem1SymbolObject != null &&
2056
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2057
                    {
2058
                        result = true;
2059
                        ReleaseCOMObjects(_LMConnector);
2060
                        break;
2061
                    }
2062
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2063
                        connector.ConnectItem2SymbolObject != null &&
2064
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2065
                    {
2066
                        result = true;
2067
                        ReleaseCOMObjects(_LMConnector);
2068
                        break;
2069
                    }
2070
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2071
                        connector.ConnectItem1SymbolObject != null &&
2072
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2073
                    {
2074
                        result = true;
2075
                        ReleaseCOMObjects(_LMConnector);
2076
                        break;
2077
                    }
2078
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2079
                        connector.ConnectItem2SymbolObject != null &&
2080
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2081
                    {
2082
                        result = true;
2083
                        ReleaseCOMObjects(_LMConnector);
2084
                        break;
2085
                    }
2086

    
2087
                    ReleaseCOMObjects(_LMConnector);
2088
                }
2089
            }
2090

    
2091

    
2092
            return result;
2093
        }
2094

    
2095
        /// <summary>
2096
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2097
        /// </summary>
2098
        /// <param name="fromModelItemId"></param>
2099
        /// <param name="toModelItemId"></param>
2100
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
2101
        {
2102
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
2103
            _LMAItem item1 = modelItem1.AsLMAItem();
2104
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
2105
            _LMAItem item2 = modelItem2.AsLMAItem();
2106
            
2107
            // item2가 item1으로 조인
2108
            try
2109
            {
2110
                _placement.PIDJoinRuns(ref item1, ref item2);
2111
                item1.Commit();
2112
                item2.Commit();
2113

    
2114
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
2115
                foreach (var line in lines)
2116
                    line.SPPID.ModelItemId = toModelItemId;
2117
            }
2118
            catch (Exception ex)
2119
            {
2120
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2121
            }
2122
            finally
2123
            {
2124
                ReleaseCOMObjects(modelItem1);
2125
                ReleaseCOMObjects(item1);
2126
                ReleaseCOMObjects(modelItem2);
2127
                ReleaseCOMObjects(item2);
2128
            }
2129
        }
2130

    
2131
        /// <summary>
2132
        /// PipeRun을 자동으로 Join하는 메서드
2133
        /// </summary>
2134
        /// <param name="modelItemId"></param>
2135
        private void AutoJoinPipeRun(string modelItemId)
2136
        {
2137
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
2138
            _LMAItem item = modelItem.AsLMAItem();
2139
            try
2140
            {
2141
                if (modelItem.get_ItemStatus() == "Active")
2142
                {
2143
                    string modelitemID = item.Id;
2144
                    _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
2145
                    string afterModelItemID = item.Id;
2146

    
2147
                    if (modelitemID != afterModelItemID)
2148
                    {
2149
                        List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
2150
                        foreach (var line in lines)
2151
                            line.SPPID.ModelItemId = afterModelItemID;
2152
                    }
2153
                    item.Commit();
2154
                }
2155
            }
2156
            catch (Exception ex)
2157
            {
2158
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2159
            }
2160
            finally
2161
            {
2162
                ReleaseCOMObjects(modelItem);
2163
                ReleaseCOMObjects(item);
2164
            }
2165
        }
2166

    
2167
        /// <summary>
2168
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
2169
        /// </summary>
2170
        /// <param name="run"></param>
2171
        private void JoinRunLine(LineRun run)
2172
        {
2173
            string modelItemId = string.Empty;
2174
            foreach (var item in run.RUNITEMS)
2175
            {
2176
                if (item.GetType() == typeof(Line))
2177
                {
2178
                    Line line = item as Line;
2179
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
2180
                    modelItemId = line.SPPID.ModelItemId;
2181

    
2182
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2183
                }
2184
            }
2185
        }
2186

    
2187
        /// <summary>
2188
        /// PipeRun의 좌표를 가져오는 메서드
2189
        /// </summary>
2190
        /// <param name="modelId"></param>
2191
        /// <returns></returns>
2192
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2193
        {
2194
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2195
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2196

    
2197
            if (modelItem != null)
2198
            {
2199
                foreach (LMRepresentation rep in modelItem.Representations)
2200
                {
2201
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2202
                    {
2203
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2204
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2205
                        dynamic OID = rep.get_GraphicOID();
2206
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2207
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2208
                        int verticesCount = lineStringGeometry.VertexCount;
2209
                        double[] vertices = null;
2210
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2211
                        for (int i = 0; i < verticesCount; i++)
2212
                        {
2213
                            double x = 0;
2214
                            double y = 0;
2215
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2216
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
2217
                        }
2218
                    }
2219
                }
2220

    
2221
                ReleaseCOMObjects(modelItem);
2222
            }
2223

    
2224
            return connectorVertices;
2225
        }
2226

    
2227
        /// <summary>
2228
        /// LMConnector들을 가져온다.
2229
        /// </summary>
2230
        /// <param name="modelId"></param>
2231
        /// <returns></returns>
2232
        private List<LMConnector> GetConnectors(string modelId)
2233
        {
2234
            List<LMConnector> connectors = new List<LMConnector>();
2235
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2236

    
2237
            if (modelItem != null)
2238
            {
2239
                foreach (LMRepresentation rep in modelItem.Representations)
2240
                {
2241
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2242
                    {
2243
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2244
                        connectors.Add(_LMConnector);
2245
                    }
2246
                }
2247

    
2248
                ReleaseCOMObjects(modelItem);
2249
            }
2250

    
2251
            return connectors;
2252
        }
2253

    
2254
        /// <summary>
2255
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함
2256
        /// </summary>
2257
        /// <param name="connectorVertices"></param>
2258
        /// <param name="connX"></param>
2259
        /// <param name="connY"></param>
2260
        /// <param name="x2"></param>
2261
        /// <param name="y2"></param>
2262
        /// <returns></returns>
2263
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
2264
        {
2265
            double length = double.MaxValue;
2266
            LMConnector targetConnector = null;
2267
            foreach (var item in connectorVertices)
2268
            {
2269
                List<double[]> points = item.Value;
2270
                for (int i = 0; i < points.Count - 1; i++)
2271
                {
2272
                    double[] point1 = points[i];
2273
                    double[] point2 = points[i + 1];
2274

    
2275
                    double maxLineX = Math.Max(point1[0], point2[0]);
2276
                    double minLineX = Math.Min(point1[0], point2[0]);
2277
                    double maxLineY = Math.Max(point1[1], point2[1]);
2278
                    double minLineY = Math.Min(point1[1], point2[1]);
2279

    
2280
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2281

    
2282
                    // 두직선의 교차점
2283
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
2284
                    if (crossingPoint != null)
2285
                    {
2286
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
2287
                        if (length >= distance)
2288
                        {
2289
                            if (slope == SlopeType.Slope &&
2290
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2291
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2292
                            {
2293
                                targetConnector = item.Key;
2294
                                length = distance;
2295
                            }
2296
                            else if (slope == SlopeType.HORIZONTAL &&
2297
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2298
                            {
2299
                                targetConnector = item.Key;
2300
                                length = distance;
2301
                            }
2302
                            else if (slope == SlopeType.VERTICAL &&
2303
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2304
                            {
2305
                                targetConnector = item.Key;
2306
                                length = distance;
2307
                            }
2308
                        }
2309
                    }
2310
                }
2311

    
2312

    
2313
            }
2314

    
2315
            if (targetConnector == null)
2316
            {
2317
                foreach (var item in connectorVertices)
2318
                {
2319
                    List<double[]> points = item.Value;
2320
                    foreach (var point in points)
2321
                    {
2322
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
2323
                        if (length >= distance)
2324
                        {
2325
                            targetConnector = item.Key;
2326
                            length = distance;
2327
                        }
2328
                    }
2329
                }
2330

    
2331
            }
2332

    
2333
            return targetConnector;
2334
        }
2335

    
2336
        /// <summary>
2337
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순)
2338
        /// </summary>
2339
        /// <param name="connectorVertices"></param>
2340
        /// <param name="connX"></param>
2341
        /// <param name="connY"></param>
2342
        /// <returns></returns>
2343
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2344
        {
2345
            double length = double.MaxValue;
2346
            LMConnector targetConnector = null;
2347
            foreach (var item in connectorVertices)
2348
            {
2349
                List<double[]> points = item.Value;
2350

    
2351
                foreach (double[] point in points)
2352
                {
2353
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2354
                    if (length >= distance)
2355
                    {
2356
                        targetConnector = item.Key;
2357
                        length = distance;
2358
                    }
2359
                }
2360
            }
2361

    
2362
            return targetConnector;
2363
        }
2364

    
2365
        /// <summary>
2366
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2367
        /// </summary>
2368
        /// <param name="connectorVertices"></param>
2369
        /// <param name="connX"></param>
2370
        /// <param name="connY"></param>
2371
        /// <returns></returns>
2372
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2373
        {
2374
            double length = double.MaxValue;
2375
            LMConnector targetConnector = null;
2376
            foreach (var item in connectorVertices)
2377
            {
2378
                List<double[]> points = item.Value;
2379
                for (int i = 0; i < points.Count - 1; i++)
2380
                {
2381
                    double[] point1 = points[i];
2382
                    double[] point2 = points[i + 1];
2383
                    double x1 = Math.Min(point1[0], point2[0]);
2384
                    double y1 = Math.Min(point1[1], point2[1]);
2385
                    double x2 = Math.Max(point1[0], point2[0]);
2386
                    double y2 = Math.Max(point1[1], point2[1]);
2387

    
2388
                    if ((x1 <= connX && x2 >= connX) ||
2389
                        (y1 <= connY && y2 >= connY))
2390
                    {
2391
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2392
                        if (length >= distance)
2393
                        {
2394
                            targetConnector = item.Key;
2395
                            length = distance;
2396
                        }
2397

    
2398
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2399
                        if (length >= distance)
2400
                        {
2401
                            targetConnector = item.Key;
2402
                            length = distance;
2403
                        }
2404
                    }
2405
                }
2406
            }
2407

    
2408
            // 못찾았을때.
2409
            length = double.MaxValue;
2410
            if (targetConnector == null)
2411
            {
2412
                foreach (var item in connectorVertices)
2413
                {
2414
                    List<double[]> points = item.Value;
2415

    
2416
                    foreach (double[] point in points)
2417
                    {
2418
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2419
                        if (length >= distance)
2420
                        {
2421
                            targetConnector = item.Key;
2422
                            length = distance;
2423
                        }
2424
                    }
2425
                }
2426
            }
2427

    
2428
            return targetConnector;
2429
        }
2430

    
2431
        /// <summary>
2432
        /// Line Number Symbol을 실제로 Modeling하는 메서드
2433
        /// </summary>
2434
        /// <param name="lineNumber"></param>
2435
        private void LineNumberModeling(LineNumber lineNumber)
2436
        {
2437
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
2438
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2439
            LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
2440
            if (connectedLMConnector != null)
2441
            {
2442
                double x = 0;
2443
                double y = 0;
2444
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
2445

    
2446
                Array points = new double[] { 0, x, y };
2447
                LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
2448

    
2449
                foreach (var item in connectorVertices)
2450
                    ReleaseCOMObjects(item.Key);
2451
                if (_LmLabelPresist != null)
2452
                {
2453
                    _LmLabelPresist.Commit();
2454
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
2455
                    ReleaseCOMObjects(_LmLabelPresist);
2456
                }
2457
                else
2458
                {
2459

    
2460
                }
2461
            }
2462

    
2463
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2464
        }
2465

    
2466
        /// <summary>
2467
        /// Flow Mark Modeling
2468
        /// </summary>
2469
        /// <param name="line"></param>
2470
        private void FlowMarkModeling(Line line)
2471
        {
2472
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
2473
            {
2474
                SlopeType targetSlopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
2475
                string mappingPath = _ETCSetting.FlowMarkSymbolPath;
2476
                double percent = line.FLOWMARK_PERCENT;
2477
                double tempX = 0;
2478
                double tempY = 0;
2479

    
2480
                double gapX;
2481
                double gapY;
2482
                // ID2 기준의 Gap을 구함
2483
                if (percent == 0)
2484
                {
2485
                    gapX = 0;
2486
                    gapY = 0;
2487
                }
2488
                else
2489
                {
2490
                    gapX = Math.Abs(line.SPPID.START_X - line.SPPID.END_X) / 100 * percent;
2491
                    gapY = Math.Abs(line.SPPID.START_Y - line.SPPID.END_Y) / 100 * percent;
2492
                }
2493

    
2494
                if (line.SPPID.START_X < line.SPPID.END_X)
2495
                    tempX = line.SPPID.START_X + gapX;
2496
                else
2497
                    tempX = line.SPPID.START_X - gapX;
2498

    
2499
                if (line.SPPID.START_Y < line.SPPID.END_Y)
2500
                    tempY = line.SPPID.START_Y + gapY;
2501
                else
2502
                    tempY = line.SPPID.START_Y - gapY;
2503

    
2504
                
2505
               
2506
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2507
                LMConnector _TargetItem = null;
2508
                double distance = double.MaxValue;
2509
                double[] startPoint = null;
2510
                double[] endPoint = null;
2511
                // ID2의 기준 Gap으로 제일 가까운 Line 찾음(Slope도 같은조건)
2512
                foreach (var item in connectorVertices)
2513
                {
2514
                    for (int i = 0; i < item.Value.Count - 1; i++)
2515
                    {
2516
                        List<double[]> points = item.Value;
2517
                        double[] point1 = points[i];
2518
                        double[] point2 = points[i + 1];
2519

    
2520
                        SlopeType slopeType = SPPIDUtil.CalcSlope(point1[0], point1[1], point2[0], point2[1]);
2521
                        if (slopeType == targetSlopeType)
2522
                        {
2523
                            double result = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], tempX, tempY);
2524
                            if (result < distance)
2525
                            {
2526
                                distance = result;
2527
                                _TargetItem = item.Key;
2528

    
2529
                                startPoint = point1;
2530
                                endPoint = point2;
2531
                            }
2532

    
2533
                            result = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], tempX, tempY);
2534
                            if (result < distance)
2535
                            {
2536
                                distance = result;
2537
                                _TargetItem = item.Key;
2538

    
2539
                                startPoint = point1;
2540
                                endPoint = point2;
2541
                            }
2542
                        }
2543
                    }
2544
                }
2545

    
2546
                if (_TargetItem != null)
2547
                {
2548
                    double x = 0;
2549
                    double y = 0;
2550
                    double angle = 0;
2551
                    // SPPID 기준의 Gap으로 실 좌표를 구함
2552
                    if (percent == 0)
2553
                    {
2554
                        gapX = 0;
2555
                        gapY = 0;
2556
                    }
2557
                    else
2558
                    {
2559
                        gapX = Math.Abs(startPoint[0] - endPoint[0]) / 100 * percent;
2560
                        gapY = Math.Abs(startPoint[1] - endPoint[1]) / 100 * percent;
2561
                    }
2562

    
2563
                    if (startPoint[0] < endPoint[0])
2564
                        x = startPoint[0] + gapX;
2565
                    else
2566
                        x = startPoint[0] - gapX;
2567

    
2568
                    if (startPoint[1] < endPoint[1])
2569
                        y = startPoint[1] + gapY;
2570
                    else
2571
                        y = startPoint[1] - gapY;
2572
                    
2573
                    if (targetSlopeType == SlopeType.HORIZONTAL)
2574
                    {
2575
                        if (startPoint[0] < endPoint[0])
2576
                            angle = 0;
2577
                        else
2578
                            angle = Math.PI;
2579
                    }
2580
                    // 90 270
2581
                    else if (targetSlopeType == SlopeType.VERTICAL)
2582
                    {
2583
                        if (startPoint[1] < endPoint[1])
2584
                            angle = 90 * Math.PI / 180;
2585
                        else
2586
                            angle = 270 * Math.PI / 180;
2587
                    }
2588

    
2589
                    LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: 0, Rotation: angle, TargetItem: _TargetItem);
2590
                    
2591
                    if (_LMSymbol != null)
2592
                    {
2593
                        ReleaseCOMObjects(_LMSymbol);
2594
                    }
2595
                        
2596
                }
2597

    
2598
                foreach (var item in connectorVertices)
2599
                    ReleaseCOMObjects(item.Key);
2600
            }
2601
        }
2602

    
2603
        /// <summary>
2604
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
2605
        /// </summary>
2606
        /// <param name="lineNumber"></param>
2607
        private void InputLineNumberAttribute(LineNumber lineNumber)
2608
        {
2609
            foreach (LineRun run in lineNumber.RUNS)
2610
            {
2611
                foreach (var item in run.RUNITEMS)
2612
                {
2613
                    if (item.GetType() == typeof(Symbol))
2614
                    {
2615
                        Symbol symbol = item as Symbol;
2616
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2617
                        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
2618

    
2619
                        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2620
                        {
2621
                            foreach (var attribute in lineNumber.ATTRIBUTES)
2622
                            {
2623
                                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2624
                                if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2625
                                {
2626
                                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
2627
                                    if (_LMAAttribute != null)
2628
                                    {
2629
                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2630
                                            _LMAAttribute.set_Value(attribute.VALUE);
2631
                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
2632
                                            _LMAAttribute.set_Value(attribute.VALUE);
2633
                                    }
2634
                                }
2635
                            }
2636
                            _LMModelItem.Commit();
2637
                        }
2638
                        if (_LMModelItem != null)
2639
                            ReleaseCOMObjects(_LMModelItem);
2640
                        if (_LMSymbol != null)
2641
                            ReleaseCOMObjects(_LMSymbol);
2642
                    }
2643
                    else if (item.GetType() == typeof(Line))
2644
                    {
2645
                        Line line = item as Line;
2646
                        if (line != null)
2647
                        {
2648
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2649
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2650
                            {
2651
                                foreach (var attribute in lineNumber.ATTRIBUTES)
2652
                                {
2653
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2654
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2655
                                    {
2656
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
2657
                                        if (_LMAAttribute != null)
2658
                                        {
2659
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2660
                                                _LMAAttribute.set_Value(attribute.VALUE);
2661
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
2662
                                                _LMAAttribute.set_Value(attribute.VALUE);
2663
                                            
2664
                                        }
2665
                                    }
2666
                                }
2667
                                _LMModelItem.Commit();
2668
                            }
2669
                            if (_LMModelItem != null)
2670
                                ReleaseCOMObjects(_LMModelItem);
2671
                        }
2672
                    }
2673
                }
2674
            }
2675

    
2676
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2677
        }
2678

    
2679
        /// <summary>
2680
        /// Symbol Attribute 입력 메서드
2681
        /// </summary>
2682
        /// <param name="item"></param>
2683
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
2684
        {
2685
            try
2686
            {
2687
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
2688
                string sRep = null;
2689
                if (targetItem.GetType() == typeof(Symbol))
2690
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
2691
                else if (targetItem.GetType() == typeof(Equipment))
2692
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
2693
                    
2694
                if (!string.IsNullOrEmpty(sRep))
2695
                {
2696
                    LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
2697
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
2698
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
2699

    
2700
                    foreach (var item in targetAttributes)
2701
                    {
2702
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
2703
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
2704
                        {
2705
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
2706
                            if (_Attribute != null)
2707
                                _Attribute.set_Value(item.VALUE);
2708
                        }
2709
                    }
2710
                    _LMModelItem.Commit();
2711
                    
2712
                    ReleaseCOMObjects(_Attributes);
2713
                    ReleaseCOMObjects(_LMModelItem);
2714
                    ReleaseCOMObjects(_LMSymbol);
2715
                }
2716
            }
2717
            catch (Exception ex)
2718
            {
2719
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2720
            }
2721

    
2722
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2723
        }
2724

    
2725
        /// <summary>
2726
        /// Input SpecBreak Attribute
2727
        /// </summary>
2728
        /// <param name="specBreak"></param>
2729
        private void InputSpecBreakAttribute(SpecBreak specBreak)
2730
        {
2731
            try
2732
            {
2733
                object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2734
                object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2735

    
2736
                if (upStreamObj != null &&
2737
                    downStreamObj != null)
2738
                {
2739
                    LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2740

    
2741
                    if (targetLMConnector != null)
2742
                    {
2743
                        foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
2744
                        {
2745
                            string symbolPath = _LMLabelPersist.get_FileName();
2746
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
2747
                            if (mapping != null)
2748
                            {
2749
                                BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
2750
                                if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2751
                                {
2752
                                    string[] values = attribute.VALUE.Split(new char[] { ',' });
2753
                                    if (values.Length == 2)
2754
                                    {
2755
                                        string upStreamValue = values[0];
2756
                                        string downStreamValue = values[1];
2757

    
2758
                                        InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
2759
                                    }
2760
                                }
2761
                            }
2762
                        }
2763

    
2764
                        ReleaseCOMObjects(targetLMConnector);
2765
                    }
2766
                }
2767
            }
2768
            catch (Exception ex)
2769
            {
2770
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2771
            }
2772

    
2773
            #region 내부에서만 쓰는 메서드
2774
            void InputAttributeForSpecBreak(object upStreamObj, object downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
2775
            {
2776
                try
2777
                {
2778
                    Symbol upStreamSymbol = upStreamObj as Symbol;
2779
                    Line upStreamLine = upStreamObj as Line;
2780
                    Symbol downStreamSymbol = downStreamObj as Symbol;
2781
                    Line downStreamLine = downStreamObj as Line;
2782
                    // 둘다 Line일 경우
2783
                    if (upStreamLine != null && downStreamLine != null)
2784
                    {
2785
                        InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
2786
                        InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
2787
                    }
2788
                    // 둘다 Symbol일 경우
2789
                    else if (upStreamSymbol != null && downStreamSymbol != null)
2790
                    {
2791
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
2792
                        LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
2793
                        LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
2794

    
2795
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
2796
                        {
2797
                            if (connector.get_ItemStatus() != "Active")
2798
                                continue;
2799

    
2800
                            if (connector.Id != zeroLenthConnector.Id)
2801
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2802
                        }
2803

    
2804
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
2805
                        {
2806
                            if (connector.get_ItemStatus() != "Active")
2807
                                continue;
2808

    
2809
                            if (connector.Id != zeroLenthConnector.Id)
2810
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2811
                        }
2812

    
2813
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
2814
                        {
2815
                            if (connector.get_ItemStatus() != "Active")
2816
                                continue;
2817

    
2818
                            if (connector.Id != zeroLenthConnector.Id)
2819
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2820
                        }
2821

    
2822
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
2823
                        {
2824
                            if (connector.get_ItemStatus() != "Active")
2825
                                continue;
2826

    
2827
                            if (connector.Id != zeroLenthConnector.Id)
2828
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2829
                        }
2830

    
2831
                        ReleaseCOMObjects(zeroLenthConnector);
2832
                        ReleaseCOMObjects(upStreamLMSymbol);
2833
                        ReleaseCOMObjects(downStreamLMSymbol);
2834
                    }
2835
                    else if (upStreamSymbol != null && downStreamLine != null)
2836
                    {
2837
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
2838
                        InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
2839
                        LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
2840

    
2841
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
2842
                        {
2843
                            if (connector.get_ItemStatus() != "Active")
2844
                                continue;
2845

    
2846
                            if (connector.Id != zeroLenthConnector.Id)
2847
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2848
                        }
2849

    
2850
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
2851
                        {
2852
                            if (connector.get_ItemStatus() != "Active")
2853
                                continue;
2854

    
2855
                            if (connector.Id != zeroLenthConnector.Id)
2856
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2857
                        }
2858

    
2859
                        ReleaseCOMObjects(zeroLenthConnector);
2860
                        ReleaseCOMObjects(upStreamLMSymbol);
2861
                    }
2862
                    else if (upStreamLine != null && downStreamSymbol != null)
2863
                    {
2864
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
2865
                        InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
2866
                        LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
2867

    
2868
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
2869
                        {
2870
                            if (connector.get_ItemStatus() != "Active")
2871
                                continue;
2872

    
2873
                            if (connector.Id != zeroLenthConnector.Id)
2874
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2875
                        }
2876

    
2877
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
2878
                        {
2879
                            if (connector.get_ItemStatus() != "Active")
2880
                                continue;
2881

    
2882
                            if (connector.Id != zeroLenthConnector.Id)
2883
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2884
                        }
2885

    
2886
                        ReleaseCOMObjects(zeroLenthConnector);
2887
                        ReleaseCOMObjects(downStreamLMSymbol);
2888
                    }
2889
                }
2890
                catch (Exception ex)
2891
                {
2892
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2893
                }
2894
            }
2895

    
2896
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
2897
            {
2898
                try
2899
                {
2900
                    LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2901
                    if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2902
                    {
2903
                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
2904
                        if (_LMAAttribute != null)
2905
                        {
2906
                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2907
                                _LMAAttribute.set_Value(value);
2908
                            else if (_LMAAttribute.get_Value() != value)
2909
                                _LMAAttribute.set_Value(value);
2910
                        }
2911

    
2912
                        _LMModelItem.Commit();
2913
                    }
2914
                    if (_LMModelItem != null)
2915
                        ReleaseCOMObjects(_LMModelItem);
2916
                }
2917
                catch (Exception ex)
2918
                {
2919
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2920
                }
2921
            }
2922

    
2923
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
2924
            {
2925
                try
2926
                {
2927
                    LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
2928
                    if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2929
                    {
2930
                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
2931
                        if (_LMAAttribute != null)
2932
                        {
2933
                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2934
                                _LMAAttribute.set_Value(value);
2935
                            else if (_LMAAttribute.get_Value() != value)
2936
                                _LMAAttribute.set_Value(value);
2937
                        }
2938

    
2939
                        _LMModelItem.Commit();
2940
                    }
2941
                    if (_LMModelItem != null)
2942
                        ReleaseCOMObjects(_LMModelItem);
2943
                }
2944
                catch (Exception ex)
2945
                {
2946
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2947
                }
2948
            }
2949
            #endregion
2950
        }
2951

    
2952
        /// <summary>
2953
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
2954
        /// </summary>
2955
        /// <param name="text"></param>
2956
        private void TextModeling(Text text)
2957
        {
2958
            LMSymbol _LMSymbol = null;
2959
            LMConnector connectedLMConnector = null;
2960
            try
2961
            {
2962
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
2963
                if (text.ASSOCIATION)
2964
                {
2965
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
2966
                    if (owner.GetType() == typeof(Symbol))
2967
                    {
2968
                        Symbol symbol = owner as Symbol;
2969
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2970
                        if (_LMSymbol != null)
2971
                        {
2972
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
2973
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
2974
                            AttributeMapping mapping = null;
2975
                            foreach (var attribute in attributes)
2976
                            {
2977
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
2978
                                    continue;
2979

    
2980
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
2981
                                if (mapping != null)
2982
                                    break;  
2983
                            }
2984

    
2985
                            if (mapping != null)
2986
                            {
2987
                                double x = 0;
2988
                                double y = 0;
2989

    
2990
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
2991
                                Array array = new double[] { 0, x, y };
2992

    
2993
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2994
                                if (_LMLabelPersist!=null)
2995
                                {
2996
                                    _LMLabelPersist.Commit();
2997
                                    ReleaseCOMObjects(_LMLabelPersist);
2998
                                }
2999
                            }
3000
                        }
3001
                    }
3002
                    else if (owner.GetType() == typeof(Line))
3003
                    {
3004
                        Line line = owner as Line;
3005
                        Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3006
                        connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
3007

    
3008
                        if (connectedLMConnector != null)
3009
                        {
3010
                            Association association = line.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
3011
                            List<BaseModel.Attribute> attributes = line.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
3012
                            AttributeMapping mapping = null;
3013
                            foreach (var attribute in attributes)
3014
                            {
3015
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
3016
                                    continue;
3017

    
3018
                                mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3019
                                if (mapping != null)
3020
                                    break;
3021
                            }
3022

    
3023
                            if (mapping != null)
3024
                            {
3025
                                double x = 0;
3026
                                double y = 0;
3027

    
3028
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3029
                                Array array = new double[] { 0, x, y };
3030

    
3031
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3032
                                if (_LMLabelPersist != null)
3033
                                {
3034
                                    _LMLabelPersist.Commit();
3035
                                    ReleaseCOMObjects(_LMLabelPersist);
3036
                                }
3037
                            }
3038
                        }
3039
                    }
3040
                }
3041
                else
3042
                {
3043
                    LMItemNote _LMItemNote = null;
3044
                    LMAAttribute _LMAAttribute = null;
3045

    
3046
                    double x = 0;
3047
                    double y = 0;
3048

    
3049
                    CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3050

    
3051
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
3052
                    _LMSymbol.Commit();
3053
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3054
                    _LMItemNote.Commit();
3055
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3056
                    _LMAAttribute.set_Value(text.VALUE);
3057
                    _LMItemNote.Commit();
3058

    
3059
                    if (_LMAAttribute != null)
3060
                        ReleaseCOMObjects(_LMAAttribute);
3061
                    if (_LMItemNote != null)
3062
                        ReleaseCOMObjects(_LMItemNote);
3063
                }
3064
            }
3065
            catch (Exception ex)
3066
            {
3067

    
3068
            }
3069
            finally
3070
            {
3071
                if (_LMSymbol != null)
3072
                    ReleaseCOMObjects(_LMSymbol);
3073
            }
3074

    
3075
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
3076
        }
3077

    
3078
        /// <summary>
3079
        /// Note Modeling
3080
        /// </summary>
3081
        /// <param name="note"></param>
3082
        private void NoteModeling(Note note)
3083
        {
3084
            LMSymbol _LMSymbol = null;
3085
            LMItemNote _LMItemNote = null;
3086
            LMAAttribute _LMAAttribute = null;
3087

    
3088
            try
3089
            {
3090
                double x = 0;
3091
                double y = 0;
3092

    
3093
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
3094

    
3095
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3096
                _LMSymbol.Commit();
3097
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3098
                _LMItemNote.Commit();
3099
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3100
                _LMAAttribute.set_Value(note.VALUE);
3101
                _LMItemNote.Commit();
3102
            }
3103
            catch (Exception ex)
3104
            {
3105

    
3106
            }
3107
            finally
3108
            {
3109
                if (_LMAAttribute != null)
3110
                    ReleaseCOMObjects(_LMAAttribute);
3111
                if (_LMItemNote != null)
3112
                    ReleaseCOMObjects(_LMItemNote);
3113
                if (_LMSymbol != null)
3114
                    ReleaseCOMObjects(_LMSymbol);
3115
            }
3116

    
3117
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
3118
        }
3119

    
3120
        /// <summary>
3121
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
3122
        /// </summary>
3123
        /// <param name="x"></param>
3124
        /// <param name="y"></param>
3125
        /// <param name="originX"></param>
3126
        /// <param name="originY"></param>
3127
        /// <param name="SPPIDLabelLocation"></param>
3128
        /// <param name="location"></param>
3129
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
3130
        {
3131
            if (location == Location.None)
3132
            {
3133
                x = originX;
3134
                y = originY;
3135
            }
3136
            else
3137
            {
3138
                if (location.HasFlag(Location.Center))
3139
                {
3140
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
3141
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
3142
                }
3143

    
3144
                if (location.HasFlag(Location.Left))
3145
                    x = SPPIDLabelLocation.X1;
3146
                else if (location.HasFlag(Location.Right))
3147
                    x = SPPIDLabelLocation.X2;
3148

    
3149
                if (location.HasFlag(Location.Down))
3150
                    y = SPPIDLabelLocation.Y1;
3151
                else if (location.HasFlag(Location.Up))
3152
                    y = SPPIDLabelLocation.Y2;
3153
            }
3154
        }
3155

    
3156
        /// <summary>
3157
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
3158
        /// 1. Angle Valve
3159
        /// 2. 3개로 이루어진 Symbol Group
3160
        /// </summary>
3161
        /// <returns></returns>
3162
        private List<Symbol> GetPrioritySymbol()
3163
        {
3164
            DataTable symbolTable = document.SymbolTable;
3165

    
3166
            // List에 순서대로 쌓는다.
3167
            List<Symbol> symbols = new List<Symbol>();
3168
            // Angle Valve 부터
3169
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2))
3170
            {
3171
                if (!symbols.Contains(symbol))
3172
                {
3173
                    double originX = 0;
3174
                    double originY = 0;
3175

    
3176
                    // ID2 Table에서 Original Point 가져옴.
3177
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}",symbol.DBUID))[0]["OriginalPoint"].ToString();
3178
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
3179

    
3180
                    SlopeType slopeType1 = SlopeType.None;
3181
                    SlopeType slopeType2 = SlopeType.None;
3182
                    foreach (Connector connector in symbol.CONNECTORS)
3183
                    {
3184
                        double connectorX = 0;
3185
                        double connectorY = 0;
3186
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3187
                        if (slopeType1 == SlopeType.None)
3188
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3189
                        else
3190
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3191
                    }
3192

    
3193
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3194
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3195
                        symbols.Add(symbol);
3196
                }
3197
            }
3198

    
3199
            // 3개의 Symbol이 뭉쳐 있을 때
3200
            foreach (var item in document.SYMBOLS)
3201
            {
3202
                List<Symbol> group = new List<Symbol>();
3203
                SPPIDUtil.FindConnectedSymbolGroup(document, item, group);
3204
                if (group.Count == 3)
3205
                {
3206
                    Symbol symbol = SPPIDUtil.FindCenterAtThreeSymbols(document, group);
3207
                    if (!symbols.Contains(symbol))
3208
                        symbols.Add(symbol);
3209
                }
3210
            }
3211

    
3212
            // Connection Point가 3개 이상
3213
            foreach (var symbol in document.SYMBOLS)
3214
                if (symbol.CONNECTORS.Count > 2 && !symbols.Contains(symbol))
3215
                    symbols.Add(symbol);
3216

    
3217
            return symbols;
3218
        }
3219

    
3220
        /// <summary>
3221
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
3222
        /// </summary>
3223
        /// <param name="graphicOID"></param>
3224
        /// <param name="milliseconds"></param>
3225
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
3226
        {
3227
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
3228
            {
3229
                double minX = 0;
3230
                double minY = 0;
3231
                double maxX = 0;
3232
                double maxY = 0;
3233
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
3234
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
3235

    
3236
                Thread.Sleep(milliseconds);
3237
            }
3238
        }
3239

    
3240
        /// <summary>
3241
        /// ComObject를 Release
3242
        /// </summary>
3243
        /// <param name="objVars"></param>
3244
        public void ReleaseCOMObjects(params object[] objVars)
3245
        {
3246
            int intNewRefCount = 0;
3247
            foreach (object obj in objVars)
3248
            {
3249
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
3250
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
3251
            }
3252
        }
3253
    }
3254
}
클립보드 이미지 추가 (최대 크기: 500 MB)