프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ ca7d0ada

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

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

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

    
37
        public string DocumentLabelText { get; set; }
38

    
39
        int CurrentCount;
40

    
41
        List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
43
        {
44
            this.document = document;
45
            this.application = application;
46
            this.radApp = radApp;
47
            this._ETCSetting = ETCSetting.GetInstance();
48
        }
49

    
50
        private int ClacProgressCount()
51
        {
52
            int EquipCount = 0;
53
            int SymbolCount = 0;
54
            int LineCount = 0;
55
            int NoteCount = 0;
56
            int TextCount = 0;
57
            int EndBreakCount = 0;
58
            int LineNumberCount = 0;
59

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

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

    
82
            return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount;
83
        }
84

    
85
        /// <summary>
86
        /// 도면 단위당 실행되는 메서드
87
        /// </summary>
88
        public void Run()
89
        {
90
            try
91
            {
92
                _placement = new Placement();
93
                dataSource = _placement.PIDDataSource;
94

    
95
                CreateDocument();
96

    
97
                if (DocumentCoordinateCorrection())
98
                {
99
                    int AllCount = ClacProgressCount();
100

    
101
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
102
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount);
103
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
104
                    Thread.Sleep(1000);
105
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
106
                    Thread.Sleep(1000);
107

    
108
                    List<List<Symbol>> symbolGroups = SPPIDUtil.GetThreeConnectedSymbolGroup(document);
109
                    foreach (List<Symbol> symbolGroup in symbolGroups)
110
                        SymbolModelingByThreeSymbolGroup(symbolGroup);
111

    
112
                    // Equipment Modeling
113
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
114
                    foreach (Equipment equipment in document.Equipments)
115
                        EquipmentModeling(equipment);
116

    
117
                    // LineRun Symbol Modeling
118
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling");
119
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
120
                        foreach (LineRun run in lineNumber.RUNS)
121
                            SymbolModelingByRun(run);
122
                    // TrimLineRun Symbol Modeling
123
                    foreach (TrimLine trimLine in document.TRIMLINES)
124
                        foreach (LineRun run in trimLine.RUNS)
125
                            SymbolModelingByRun(run);
126

    
127
                    // LineRun Line Modeling
128
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
129
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
130
                        foreach (LineRun run in lineNumber.RUNS)
131
                            LineModelingByRun(run);
132
                    // TrimLineRun Line Modeling
133
                    foreach (TrimLine trimLine in document.TRIMLINES)
134
                        foreach (LineRun run in trimLine.RUNS)
135
                            LineModelingByRun(run);
136

    
137
                    // Branch Line Modeling
138
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
139
                    foreach (var item in BranchLines)
140
                        BranchLineModeling(item);
141

    
142
                    // EndBreak Modeling
143
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
144
                    foreach (var item in document.EndBreaks)
145
                        EndBreakModeling(item);
146

    
147
                    // LineNumber Modeling
148
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling");
149
                    foreach (var item in document.LINENUMBERS)
150
                        LineNumberModeling(item);
151

    
152
                    // Note Modeling
153
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
154
                    foreach (var item in document.NOTES)
155
                        NoteModeling(item);
156

    
157
                    // Text Modeling
158
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
159
                    foreach (var item in document.TEXTINFOS)
160
                        TextModeling(item);
161

    
162
                    // LineRun Line Join
163
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
164
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
165
                        foreach (LineRun run in lineNumber.RUNS)
166
                            JoinRunLine(run);
167
                    // TrimLineRun Line Join
168
                    foreach (TrimLine trimLine in document.TRIMLINES)
169
                        foreach (LineRun run in trimLine.RUNS)
170
                            JoinRunLine(run);
171

    
172
                    // Input LineNumber Attribute
173
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute");
174
                    foreach (var item in document.LINENUMBERS)
175
                        InputLineNumberAttribute(item);
176

    
177
                    // Input Symbol Attribute
178
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
179
                    foreach (var item in document.SYMBOLS)
180
                        InputSymbolAttribute(item, item.ATTRIBUTES);
181

    
182
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
183
                    foreach (var item in document.SYMBOLS)
184
                        LabelSymbolModeling(item);
185

    
186
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount);
187
                }
188
            }
189
            catch (Exception ex)
190
            {
191
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
192
            }
193
            finally
194
            {
195
                application.ActiveWindow.Fit();
196
                
197
                if (newDrawing != null)
198
                {
199
                    radApp.ActiveDocument.SaveOnClose = false;
200
                    radApp.ActiveDocument.Save();
201
                    ReleaseCOMObjects(newDrawing);
202
                }
203

    
204
                ReleaseCOMObjects(dataSource);
205
                ReleaseCOMObjects(_placement);
206

    
207
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
208
                SplashScreenManager.CloseForm(false);
209
            }
210
        }
211

    
212
        /// <summary>
213
        /// 도면 생성 메서드
214
        /// </summary>
215
        private void CreateDocument()
216
        {
217
            newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
218
            application.ActiveWindow.Fit();
219
            Thread.Sleep(1000);
220
            application.ActiveWindow.Zoom = 2000;
221
            Thread.Sleep(2000);
222
        }
223

    
224
        /// <summary>
225
        /// 도면 크기 구하는 메서드
226
        /// </summary>
227
        /// <returns></returns>
228
        private bool DocumentCoordinateCorrection()
229
        {
230
            double maxX = 0;
231
            double maxY = 0;
232
            foreach (object drawingObj in radApp.ActiveDocument.ActiveSheet.DrawingObjects)
233
            {
234
                Ingr.RAD2D.SmartFrame2d smartFrame2d = drawingObj as Ingr.RAD2D.SmartFrame2d;
235
                if (smartFrame2d != null)
236
                {
237
                    double x1 = 0;
238
                    double x2 = 0;
239
                    double y1 = 0;
240
                    double y2 = 0;
241
                    smartFrame2d.Range(out x1, out y1, out x2, out y2);
242
                    maxX = Math.Max(x2, maxX);
243
                    maxY = Math.Max(y2, maxY);
244
                }
245
            }
246
            if (maxX != 0 && maxY != 0)
247
            {
248
                document.SetSPPIDLocation(maxX, maxY);
249
                return true;
250
            }
251
            else
252
                return false;
253
        }
254

    
255
        /// <summary>
256
        /// 라인을 Run 단위로 모델링하는 진입 메서드
257
        /// </summary>
258
        /// <param name="run"></param>
259
        private void LineModelingByRun(LineRun run)
260
        {
261
            Line prevLine = null;
262
            List<Line> lines = new List<Line>();
263
            foreach (var item in run.RUNITEMS)
264
            {
265
                // Line일 경우
266
                if (item.GetType() == typeof(Line))
267
                {
268
                    Line line = item as Line;
269
                    if (prevLine == null)
270
                        lines.Add(line);
271
                    else if (prevLine != null)
272
                    {
273
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
274
                            lines.Add(line);
275
                        else
276
                        {
277
                            if (lines.Count > 0)
278
                            {
279
                                LineModeling(lines);
280
                                lines.Clear();
281
                            }
282
                            lines.Add(line);
283
                        }
284
                    }
285

    
286
                    prevLine = line;
287

    
288
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
289
                }
290
                // Symbol 일 경우
291
                else if (item.GetType() == typeof(Symbol))
292
                {
293
                    if (lines.Count > 0)
294
                    {
295
                        LineModeling(lines);
296
                        lines.Clear();
297
                    }
298
                }
299
            }
300

    
301
            if (lines.Count > 0)
302
                LineModeling(lines);
303
        }
304

    
305
        /// <summary>
306
        /// 심볼을 Run 단위로 모델링하는 진입 메서드
307
        /// </summary>
308
        /// <param name="run"></param>
309
        private void SymbolModelingByRun(LineRun run)
310
        {
311
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
312
            if (run.RUNITEMS.Count > 0)
313
            {
314
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
315
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
316

    
317
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
318
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
319
            }
320

    
321
            Symbol prevSymbol = null;
322
            Symbol targetSymbol = null;
323
            foreach (var item in run.RUNITEMS)
324
            {
325
                if (item.GetType() == typeof(Symbol))
326
                {
327
                    Symbol symbol = item as Symbol;
328
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
329
                    prevSymbol = symbol;
330
                    targetSymbol = symbol;
331
                }
332
                else
333
                {
334
                    targetSymbol = null;
335
                }
336
            }
337
        }
338

    
339
        /// <summary>
340
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점
341
        /// </summary>
342
        /// <param name="symbol"></param>
343
        /// <param name="run"></param>
344
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
345
        {
346
            foreach (var connector in symbol.CONNECTORS)
347
            {
348
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
349
                if (targetItem != null &&
350
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
351
                    !IsSameLineRun(symbol, targetItem))
352
                {
353
                    SymbolModeling(symbol, targetItem as Symbol, null);
354
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
355
                    {
356
                        object item = run.RUNITEMS[i];
357
                        if (item.GetType() == typeof(Symbol))
358
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
359
                        else
360
                            break;
361
                    }
362
                    break;
363
                }
364
            }
365

    
366

    
367
        }
368

    
369
        /// <summary>
370
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점
371
        /// </summary>
372
        /// <param name="symbol"></param>
373
        /// <param name="run"></param>
374
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
375
        {
376
            foreach (var connector in symbol.CONNECTORS)
377
            {
378
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
379
                if (targetItem != null &&
380
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
381
                    !IsSameLineRun(symbol, targetItem))
382
                {
383
                    SymbolModeling(symbol, targetItem as Symbol, null);
384
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
385
                    {
386
                        object item = run.RUNITEMS[i];
387
                        if (item.GetType() == typeof(Symbol))
388
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
389
                        else
390
                            break;
391
                    }
392
                    break;
393
                }
394
            }
395
        }
396

    
397
        /// <summary>
398
        /// 심볼을 실제로 Modeling 메서드
399
        /// </summary>
400
        /// <param name="symbol"></param>
401
        /// <param name="targetSymbol"></param>
402
        /// <param name="prevSymbol"></param>
403
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
404
        {
405
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
406
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
407
            if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None")
408
                return;
409
            // 이미 모델링 됐을 경우
410
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
411
                return;
412

    
413
            LMSymbol _LMSymbol = null;
414

    
415
            string mappingPath = symbol.SPPID.MAPPINGNAME;
416
            double x = symbol.SPPID.ORIGINAL_X;
417
            double y = symbol.SPPID.ORIGINAL_Y;
418
            int mirror = 0;
419
            double angle = symbol.ANGLE;
420

    
421
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
422

    
423
            // OPC 일경우 180도 일때 Mirror
424
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
425
                mirror = 1;
426

    
427
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
428
            {
429
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
430
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
431
                if (connector != null)
432
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
433

    
434
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
435
                ReleaseCOMObjects(_TargetItem);
436
            }
437
            else if (prevSymbol != null)
438
            {
439
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
440
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
441
                double prevX = _PrevSymbol.get_XCoordinate();
442
                double prevY = _PrevSymbol.get_YCoordinate();
443
                //if (slopeType == SlopeType.HORIZONTAL)
444
                //    y = prevY;
445
                //else if (slopeType == SlopeType.VERTICAL)
446
                //    x = prevX;
447
                ReleaseCOMObjects(_PrevSymbol);
448
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
449
            }
450
            else
451
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
452

    
453

    
454
            if (_LMSymbol != null)
455
            {
456
                _LMSymbol.Commit();
457
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
458
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
459

    
460
                foreach (var item in symbol.ChildSymbols)
461
                    CreateChildSymbol(item, _LMSymbol);
462
            }
463

    
464
            ReleaseCOMObjects(_LMSymbol);
465
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
466
        }
467

    
468
        /// <summary>
469
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
470
        /// </summary>
471
        /// <param name="targetConnector"></param>
472
        /// <param name="targetSymbol"></param>
473
        /// <param name="x"></param>
474
        /// <param name="y"></param>
475
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
476
        {
477
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
478

    
479
            double[] range = null;
480
            List<double[]> points = new List<double[]>();
481
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
482
            double x1 = range[0];
483
            double y1 = range[1];
484
            double x2 = range[2];
485
            double y2 = range[3];
486

    
487
            // Origin 기준 Connector의 위치차이
488
            double sceneX = 0;
489
            double sceneY = 0;
490
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
491
            double originX = 0;
492
            double originY = 0;
493
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
494
            double gapX = originX - sceneX;
495
            double gapY = originY - sceneY;
496

    
497
            // SPPID Symbol과 ID2 심볼의 크기 차이
498
            double sizeWidth = 0;
499
            double sizeHeight = 0;
500
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
501
            double percentX = (x2 - x1) / sizeWidth;
502
            double percentY = (y2 - y1) / sizeHeight;
503

    
504
            double SPPIDgapX = gapX * percentX;
505
            double SPPIDgapY = gapY * percentY;
506

    
507
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
508
            double distance = double.MaxValue;
509
            double[] resultPoint;
510
            foreach (var point in points)
511
            {
512
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
513
                if (distance > result)
514
                {
515
                    distance = result;
516
                    resultPoint = point;
517
                    x = point[0];
518
                    y = point[1];
519
                }
520
            }
521

    
522
            ReleaseCOMObjects(_TargetItem);
523
        }
524

    
525
        /// <summary>
526
        /// SPPID Symbol의 Range를 구한다.
527
        /// </summary>
528
        /// <param name="symbol"></param>
529
        /// <param name="range"></param>
530
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
531
        {
532
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
533
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
534
            double x1 = 0;
535
            double y1 = 0;
536
            double x2 = 0;
537
            double y2 = 0;
538
            symbol2d.Range(out x1, out y1, out x2, out y2);
539
            range = new double[] { x1, y1, x2, y2 };
540

    
541
            for (int i = 1; i < int.MaxValue; i++)
542
            {
543
                double connX = 0;
544
                double connY = 0;
545
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
546
                    points.Add(new double[] { connX, connY });
547
                else
548
                    break;
549
            }
550

    
551
            foreach (var childSymbol in symbol.ChildSymbols)
552
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
553

    
554
            ReleaseCOMObjects(_TargetItem);
555
        }
556

    
557
        /// <summary>
558
        /// Child Modeling 된 Symbol의 Range를 구한다.
559
        /// </summary>
560
        /// <param name="childSymbol"></param>
561
        /// <param name="range"></param>
562
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
563
        {
564
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
565
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
566
            double x1 = 0;
567
            double y1 = 0;
568
            double x2 = 0;
569
            double y2 = 0;
570
            symbol2d.Range(out x1, out y1, out x2, out y2);
571
            range[0] = Math.Min(range[0], x1);
572
            range[1] = Math.Min(range[1], y1);
573
            range[2] = Math.Max(range[2], x2);
574
            range[3] = Math.Max(range[3], y2);
575

    
576
            for (int i = 1; i < int.MaxValue; i++)
577
            {
578
                double connX = 0;
579
                double connY = 0;
580
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
581
                    points.Add(new double[] { connX, connY });
582
                else
583
                    break;
584
            }
585

    
586
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
587
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
588

    
589
            ReleaseCOMObjects(_ChildSymbol);
590
        }
591

    
592
        /// <summary>
593
        /// Label Symbol Modeling
594
        /// </summary>
595
        /// <param name="symbol"></param>
596
        private void LabelSymbolModeling(Symbol symbol)
597
        {
598
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
599
            if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE))
600
                return;
601

    
602
            Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
603
            
604
            string symbolUID = itemAttribute.VALUE;
605
            object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
606
            if (targetItem != null)
607
            {
608
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
609
                string sRep = null;
610
                if (targetItem.GetType() == typeof(Symbol))
611
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
612
                else if (targetItem.GetType() == typeof(Equipment))
613
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
614

    
615
                if (!string.IsNullOrEmpty(sRep))
616
                {
617
                    // LEADER Line 검사
618
                    bool leaderLine = false;
619
                    SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
620
                    if (symbolMapping != null)
621
                        leaderLine = symbolMapping.LEADERLINE;
622

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

    
627
                    // Target Item에 Label의 Attribute Input
628
                    InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
629

    
630
                    //Leader 선 센터로
631
                    string OID = _LMLabelPresist.get_GraphicOID();
632
                    DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
633
                    if (dependency != null)
634
                    {
635
                        bool result = false;
636
                        foreach (var attributes in dependency.AttributeSets)
637
                        {
638
                            foreach (var attribute in attributes)
639
                            {
640
                                string name = attribute.Name;
641
                                string value = attribute.GetValue().ToString();
642
                                if (name == "DrawingItemType" && value == "LabelPersist")
643
                                {
644
                                    foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
645
                                    {
646
                                        if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
647
                                        {
648
                                            Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
649
                                            double prevX = _TargetItem.get_XCoordinate();
650
                                            double prevY = _TargetItem.get_YCoordinate();
651
                                            lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
652
                                            lineString2D.RemoveVertex(lineString2D.VertexCount);
653
                                            result = true;
654
                                            break;
655
                                        }
656
                                    }
657
                                }
658

    
659
                                if (result)
660
                                    break;
661
                            }
662

    
663
                            if (result)
664
                                break;
665
                        }
666
                    }
667

    
668
                    _LMLabelPresist.Commit();
669
                    ReleaseCOMObjects(_TargetItem);
670
                    ReleaseCOMObjects(_LMLabelPresist);
671
                }
672
            }
673

    
674
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
675
        }
676

    
677
        /// <summary>
678
        /// Equipment를 실제로 Modeling 메서드
679
        /// </summary>
680
        /// <param name="equipment"></param>
681
        private void EquipmentModeling(Equipment equipment)
682
        {
683
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
684
                return;
685

    
686
            LMSymbol _LMSymbol = null;
687
            LMSymbol targetItem = null;
688
            string mappingPath = equipment.SPPID.MAPPINGNAME;
689
            double x = equipment.SPPID.ORIGINAL_X;
690
            double y = equipment.SPPID.ORIGINAL_Y;
691
            int mirror = 0;
692
            double angle = equipment.ANGLE;
693

    
694
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
695

    
696
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
697
            if (connector != null)
698
            {
699
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
700
                if (connEquipment != null)
701
                {
702
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
703
                        EquipmentModeling(connEquipment);
704

    
705
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
706
                    {
707
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
708
                        if (targetItem != null)
709
                        {
710
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
711
                        }
712
                        else
713
                        {
714
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
715
                        }
716
                    }
717
                    else
718
                    {
719
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
720
                    }
721
                }
722
                else
723
                {
724
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
725
                }
726
            }
727
            else
728
            {
729
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
730
            }
731

    
732
            if (_LMSymbol != null)
733
            {
734
                _LMSymbol.Commit();
735
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
736
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
737
                ReleaseCOMObjects(_LMSymbol);
738
            }
739

    
740
            if (targetItem != null)
741
            {
742
                ReleaseCOMObjects(targetItem);
743
            }
744
            
745
            ReleaseCOMObjects(_LMSymbol);
746

    
747
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
748
        }
749

    
750
        /// <summary>
751
        /// 3개의 Symbol이 붙어있을경우 CenterSymbol을 Grid기준으로 맞추기 위해서 모델링
752
        /// </summary>
753
        /// <param name="group"></param>
754
        private void SymbolModelingByThreeSymbolGroup(List<Symbol> group)
755
        {
756
            // Group의 가운데 찾기
757
            Symbol symbol1 = null;
758
            Symbol symbol2 = null;
759
            Symbol centerSymbol = null;
760
            foreach (var symbol in group)
761
            {
762
                int count = 0;
763
                foreach (var connector in symbol.CONNECTORS)
764
                {
765
                    object item = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
766
                    if (item != null && item.GetType() == typeof(Symbol))
767
                        count++;
768
                }
769

    
770
                // Center Symbol
771
                if (count == 2)
772
                {
773
                    SymbolModeling(symbol, null, null);
774
                    centerSymbol = symbol;
775
                }
776
                else if (symbol1 == null)
777
                    symbol1 = symbol;
778
                else
779
                    symbol2 = symbol;
780
            }
781

    
782
            SymbolModeling(symbol1, centerSymbol, null);
783
            SymbolModeling(symbol2, centerSymbol, null);
784
        }
785

    
786
        /// <summary>
787
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
788
        /// </summary>
789
        /// <param name="childSymbol"></param>
790
        /// <param name="parentSymbol"></param>
791
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
792
        {
793
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
794
            double x1 = 0;
795
            double x2 = 0;
796
            double y1 = 0;
797
            double y2 = 0;
798
            symbol2d.Range(out x1, out y1, out x2, out y2);
799

    
800
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
801
            if (_LMSymbol != null)
802
            {
803
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
804
                foreach (var item in childSymbol.ChildSymbols)
805
                    CreateChildSymbol(item, _LMSymbol);
806
            }
807
            
808

    
809
            ReleaseCOMObjects(_LMSymbol);
810
        }
811

    
812
        /// <summary>
813
        /// item이 TargetItem과 같은 LineRun에 있는지 검사
814
        /// </summary>
815
        /// <param name="item"></param>
816
        /// <param name="targetItem"></param>
817
        /// <returns></returns>
818
        private bool IsSameLineRun(object item, object targetItem)
819
        {
820
            foreach (var lineNumber in document.LINENUMBERS)
821
            {
822
                foreach (var run in lineNumber.RUNS)
823
                {
824
                    foreach (var runItem in run.RUNITEMS)
825
                    {
826
                        if (runItem == item)
827
                        {
828
                            foreach (var findItem in run.RUNITEMS)
829
                            {
830
                                if (findItem == targetItem)
831
                                {
832
                                    return true;
833
                                }
834
                            }
835

    
836
                            return false;
837

    
838
                        }
839
                    }
840
                }
841
            }
842

    
843
            return false;
844
        }
845

    
846
        /// <summary>
847
        /// Line을 실제로 모델링하는 메서드
848
        /// </summary>
849
        /// <param name="lines"></param>
850
        private void LineModeling(List<Line> lines)
851
        {
852
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
853
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
854
            LMSymbol _LMSymbol1 = null;
855
            LMSymbol _LMSymbol2 = null;
856
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
857
            LMConnector targetConnector1 = null;
858
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
859
            LMConnector targetConnector2 = null;
860

    
861
            Line startBranchLine = null;
862
            Line endBranchLine = null;
863

    
864
            // Type, TargetObjet, x, y
865
            List<Tuple<string, object, double, double>> linePointInfo = new List<Tuple<string, object, double, double>>();
866

    
867
            for (int i = 0; i < lines.Count; i++)
868
            {
869
                Line line = lines[i];
870
                if (i == 0 || i + 1 != lines.Count)
871
                {
872
                    // 시작점에 연결된 Symbol 찾기
873
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
874
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
875
                    {
876
                        Symbol symbol1 = connItem as Symbol;
877
                        _LMSymbol1 = GetTargetSymbol(symbol1, line);
878
                        if (_LMSymbol1 != null)
879
                        {
880
                            double x = line.SPPID.START_X;
881
                            double y = line.SPPID.START_Y;
882
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1);
883
                            if (connector != null)
884
                            {
885
                                GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y);
886
                                line.SPPID.START_X = x;
887
                                line.SPPID.START_Y = y;
888
                            }
889

    
890
                            linePointInfo.Add(new Tuple<string, object, double, double>("SYMBOL", _LMSymbol1, x, y));
891
                        }
892
                        else
893
                            linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.START_X, line.SPPID.START_Y));
894
                    }
895
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
896
                    {
897
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
898
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
899

    
900
                        if (targetConnector1 != null)
901
                            linePointInfo.Add(new Tuple<string, object, double, double>("LINE", targetConnector1, line.SPPID.START_X, line.SPPID.START_Y));
902
                        else
903
                        {
904
                            startBranchLine = connItem as Line;
905
                            linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.START_X, line.SPPID.START_Y));
906
                        }
907
                    }
908
                    else
909
                        linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.START_X, line.SPPID.START_Y));
910
                        
911
                }
912
                if (i + 1 == lines.Count)
913
                {
914
                    // 끝점에 연결된 Symbol 찾기
915
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
916

    
917
                    if (i != 0)
918
                        linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.START_X, line.SPPID.START_Y));
919

    
920
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
921
                    {
922
                        Symbol symbol2 = connItem as Symbol;
923
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
924
                        if (_LMSymbol2 != null)
925
                        {
926
                            double x = line.SPPID.END_X;
927
                            double y = line.SPPID.END_Y;
928
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2);
929
                            if (connector != null)
930
                            {
931
                                GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y);
932
                                line.SPPID.END_X = x;
933
                                line.SPPID.END_Y = y;
934
                            }
935

    
936
                            linePointInfo.Add(new Tuple<string, object, double, double>("SYMBOL", _LMSymbol2, x, y));
937
                        }
938
                        else
939
                            linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.END_X, line.SPPID.END_Y));
940
                    }
941
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
942
                    {
943
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
944
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
945

    
946
                        if (targetConnector2 != null)
947
                            linePointInfo.Add(new Tuple<string, object, double, double>("LINE", targetConnector2, line.SPPID.END_X, line.SPPID.END_Y));
948
                        else
949
                        {
950
                            endBranchLine = connItem as Line;
951
                            linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.END_X, line.SPPID.END_Y));
952
                        }
953
                    }
954
                    else
955
                        linePointInfo.Add(new Tuple<string, object, double, double>(null, null, line.SPPID.END_X, line.SPPID.END_Y));
956
                }
957
            }
958

    
959
            for (int i = 0; i < linePointInfo.Count; i++)
960
            {
961
                Tuple<string, object, double, double> item = linePointInfo[i];
962
                if (item.Item1 == "SYMBOL")
963
                    placeRunInputs.AddSymbolTarget(item.Item2 as LMSymbol, item.Item3, item.Item4);
964
                else if (item.Item1 == "LINE")
965
                    placeRunInputs.AddConnectorTarget(item.Item2 as LMConnector, item.Item3, item.Item4);
966
                else
967
                    placeRunInputs.AddPoint(item.Item3, item.Item4);
968
            }
969

    
970
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
971

    
972
            if (_lMConnector != null)
973
            {
974
                foreach (var line in lines)
975
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
976
                _lMConnector.Commit();
977
                if (startBranchLine != null || endBranchLine != null)
978
                {
979
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
980
                }
981
            }
982

    
983

    
984
            if (_LMSymbol1 != null)
985
                ReleaseCOMObjects(_LMSymbol1);
986
            if (_LMSymbol2 != null)
987
                ReleaseCOMObjects(_LMSymbol2);
988
            if (targetConnector1 != null)
989
                ReleaseCOMObjects(targetConnector1);
990
            if (targetConnector2 != null)
991
                ReleaseCOMObjects(targetConnector2);
992
            foreach (var item in connectorVertices1)
993
                ReleaseCOMObjects(item.Key);
994
            foreach (var item in connectorVertices2)
995
                ReleaseCOMObjects(item.Key);
996

    
997
            ReleaseCOMObjects(_lMConnector);
998
            ReleaseCOMObjects(placeRunInputs);
999
            ReleaseCOMObjects(_LMAItem);
1000
        }
1001

    
1002
        /// <summary>
1003
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
1004
        /// </summary>
1005
        /// <param name="symbol"></param>
1006
        /// <param name="line"></param>
1007
        /// <returns></returns>
1008
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
1009
        {
1010
            LMSymbol _LMSymbol = null;
1011
            foreach (var connector in symbol.CONNECTORS)
1012
            {
1013
                if (connector.CONNECTEDITEM == line.UID)
1014
                {
1015
                    if (connector.Index == 0)
1016
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1017
                    else
1018
                    {
1019
                        ChildSymbol child = null;
1020
                        foreach (var childSymbol in symbol.ChildSymbols)
1021
                        {
1022
                            if (childSymbol.Connectors.Contains(connector))
1023
                                child = childSymbol;
1024
                            else
1025
                                child = GetChildSymbolByConnector(childSymbol, connector);
1026

    
1027
                            if (child != null)
1028
                                break;
1029
                        }
1030

    
1031
                        if (child != null)
1032
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
1033
                    }
1034

    
1035
                    break;  
1036
                }
1037
            }
1038

    
1039
            return _LMSymbol;
1040
        }
1041

    
1042
        /// <summary>
1043
        /// Connector를 가지고 있는 ChildSymbol Object 반환
1044
        /// </summary>
1045
        /// <param name="item"></param>
1046
        /// <param name="connector"></param>
1047
        /// <returns></returns>
1048
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
1049
        {
1050
            foreach (var childSymbol in item.ChildSymbols)
1051
            {
1052
                if (childSymbol.Connectors.Contains(connector))
1053
                    return childSymbol;
1054
                else
1055
                    return GetChildSymbolByConnector(childSymbol, connector);
1056
            }
1057

    
1058
            return null;
1059
        }
1060

    
1061
        /// <summary>
1062
        /// Branch 라인을 다시 모델링하는 진입 메서드
1063
        /// </summary>
1064
        /// <param name="branch"></param>
1065
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
1066
        {
1067
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1068
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1069

    
1070
            LMConnector _StartConnector = null;
1071
            LMConnector _EndConnector = null;
1072
            double lengthStart = double.MaxValue;
1073
            double lengthEnd = double.MaxValue;
1074
            List<double[]> startPoints = new List<double[]>();
1075
            List<double[]> endPoints = new List<double[]>();
1076

    
1077
            foreach (var item in connectorVertices)
1078
            {
1079
                foreach (var point in item.Value)
1080
                {
1081
                    // Start Point가 Branch
1082
                    if (branch.Item2 != null)
1083
                    {
1084
                        Line targetLine = branch.Item2;
1085
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1086
                        if (lengthStart > distance)
1087
                        {
1088
                            _StartConnector = item.Key;
1089
                            lengthStart = distance;
1090
                            startPoints = item.Value;
1091
                        }
1092
                    }
1093
                    // End Point가 Branch
1094
                    if (branch.Item3 != null)
1095
                    {
1096
                        Line targetLine = branch.Item3;
1097
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1098
                        if (lengthEnd > distance)
1099
                        {
1100
                            _EndConnector = item.Key;
1101
                            lengthEnd = distance;
1102
                            endPoints = item.Value;
1103
                        }
1104
                    }
1105
                }
1106
            }
1107
            #region Branch가 양쪽 전부일 때
1108
            if (_StartConnector != null && _StartConnector == _EndConnector)
1109
            {
1110
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
1111

    
1112
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1113
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1114

    
1115
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1116
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
1117
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1118
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
1119
                   startPoints[startPoints.Count - 1][0],
1120
                   startPoints[startPoints.Count - 1][1],
1121
                   startPoints[startPoints.Count - 2][0],
1122
                   startPoints[startPoints.Count - 2][1]);
1123

    
1124
                for (int i = 0; i < startPoints.Count; i++)
1125
                {
1126
                    double[] point = startPoints[i];
1127
                    if (i == 0)
1128
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
1129
                    else if (i == startPoints.Count - 1)
1130
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
1131
                    else
1132
                        placeRunInputs.AddPoint(point[0], point[1]);
1133
                }
1134

    
1135
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1136
                if (_LMConnector != null)
1137
                {
1138
                    _LMConnector.Commit();
1139
                    foreach (var item in lines)
1140
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1141
                }
1142

    
1143
                foreach (var item in startConnectorVertices)
1144
                    ReleaseCOMObjects(item.Key);
1145
                foreach (var item in endConnectorVertices)
1146
                    ReleaseCOMObjects(item.Key);
1147
                ReleaseCOMObjects(placeRunInputs);
1148
                ReleaseCOMObjects(_LMAItem);
1149
                ReleaseCOMObjects(_LMConnector);
1150
            }
1151
            #endregion
1152
            #region 양쪽이 다른 Branch 
1153
            else
1154
            {
1155
                // Branch 시작 Connector
1156
                if (_StartConnector != null)
1157
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
1158

    
1159
                // Branch 끝 Connector
1160
                if (_EndConnector != null)
1161
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
1162
            }
1163
            #endregion
1164

    
1165
            if (_StartConnector != null)
1166
                ReleaseCOMObjects(_StartConnector);
1167
            if (_EndConnector != null)
1168
                ReleaseCOMObjects(_EndConnector);
1169
            foreach (var item in connectorVertices)
1170
                ReleaseCOMObjects(item.Key);
1171
        }
1172

    
1173
        /// <summary>
1174
        /// Branch 라인을 다시 실제로 모델링하는 메서드
1175
        /// </summary>
1176
        /// <param name="branch"></param>
1177
        /// <param name="_Connector"></param>
1178
        /// <param name="points"></param>
1179
        /// <param name="IsStart"></param>
1180
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
1181
        {
1182
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1183
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1184
            LMConnector _SameRunTargetConnector = null;
1185
            LMSymbol _SameRunTargetSymbol = null;
1186
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
1187
            LMConnector _BranchTargetConnector = null;
1188
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1189

    
1190
            // 같은 Line Run의 Connector 찾기
1191
            foreach (var item in connectorVertices)
1192
            {
1193
                if (item.Key == _Connector)
1194
                    continue;
1195

    
1196
                if (IsStart &&
1197
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
1198
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
1199
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
1200
                {
1201
                    _SameRunTargetConnector = item.Key;
1202
                    break;
1203
                }
1204
                else if (!IsStart &&
1205
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
1206
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
1207
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
1208
                {
1209
                    _SameRunTargetConnector = item.Key;
1210
                    break;
1211
                }
1212
            }
1213

    
1214
            // Branch 반대편이 Symbol
1215
            if (_SameRunTargetConnector == null)
1216
            {
1217
                foreach (var line in lines)
1218
                {
1219
                    foreach (var connector in line.CONNECTORS)
1220
                    {
1221
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
1222
                        if (symbol != null)
1223
                        {
1224
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1225
                            break;
1226
                        }
1227
                    }
1228
                }
1229
            }
1230

    
1231
            // 기존 Connector 제거
1232
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
1233
            
1234
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
1235
            if (IsStart)
1236
            {
1237
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1238
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
1239
            }
1240
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
1241
            else
1242
            {
1243
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1244
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
1245
                    points[points.Count - 1][0],
1246
                    points[points.Count - 1][1],
1247
                    points[points.Count - 2][0],
1248
                    points[points.Count - 2][1]);
1249
            }
1250

    
1251
            for (int i = 0; i < points.Count; i++)
1252
            {
1253
                double[] point = points[i];
1254
                if (i == 0)
1255
                {
1256
                    if (IsStart)
1257
                    {
1258
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1259
                    }
1260
                    else
1261
                    {
1262
                        if (_SameRunTargetConnector != null)
1263
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1264
                        else if (_SameRunTargetSymbol != null)
1265
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1266
                        else
1267
                            placeRunInputs.AddPoint(point[0], point[1]);
1268
                    }
1269
                }
1270
                else if (i == points.Count - 1)
1271
                {
1272
                    if (IsStart)
1273
                    {
1274
                        if (_SameRunTargetConnector != null)
1275
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1276
                        else if (_SameRunTargetSymbol != null)
1277
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1278
                        else
1279
                            placeRunInputs.AddPoint(point[0], point[1]);
1280
                    }
1281
                    else
1282
                    {
1283
                        if (_BranchTargetConnector != null)
1284
                        {
1285
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1286
                        }
1287
                    }
1288
                }
1289
                else
1290
                    placeRunInputs.AddPoint(point[0], point[1]);
1291
            }
1292
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1293
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1294

    
1295
            if (_LMConnector != null)
1296
            {
1297
                if (_SameRunTargetConnector != null)
1298
                {
1299
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
1300
                }
1301
                else
1302
                {
1303
                    foreach (var item in lines)
1304
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1305
                }
1306

    
1307
                _LMConnector.Commit();
1308
                ReleaseCOMObjects(_LMConnector);
1309
            }
1310

    
1311
            ReleaseCOMObjects(placeRunInputs);
1312
            ReleaseCOMObjects(_LMAItem);
1313
            if (_BranchTargetConnector != null)
1314
                ReleaseCOMObjects(_BranchTargetConnector);
1315
            if (_SameRunTargetConnector != null)
1316
                ReleaseCOMObjects(_SameRunTargetConnector);
1317
            if (_SameRunTargetSymbol != null)
1318
                ReleaseCOMObjects(_SameRunTargetSymbol);
1319
            foreach (var item in connectorVertices)
1320
                ReleaseCOMObjects(item.Key);
1321
            foreach (var item in branchConnectorVertices)
1322
                ReleaseCOMObjects(item.Key);
1323
        }
1324

    
1325
        /// <summary>
1326
        /// EndBreak 모델링 메서드
1327
        /// </summary>
1328
        /// <param name="endBreak"></param>
1329
        private void EndBreakModeling(EndBreak endBreak)
1330
        {
1331
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
1332
            LMConnector targetLMConnector = null;
1333
            if (ownerObj !=null && ownerObj.GetType() == typeof(Line))
1334
            {
1335
                Line ownerLine = ownerObj as Line;
1336
                LMLabelPersist _LmLabelPersist = null;
1337
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
1338

    
1339
                targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1340
                
1341
                if (targetLMConnector != null)
1342
                {
1343
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1344
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1345
                }
1346

    
1347
                if (_LmLabelPersist != null)
1348
                {
1349
                    _LmLabelPersist.Commit();
1350
                    ReleaseCOMObjects(_LmLabelPersist);
1351
                }
1352
                else
1353
                    RetryEndBreakModeling(endBreak, targetLMConnector);
1354

    
1355
                foreach (var item in connectorVertices)
1356
                    ReleaseCOMObjects(item.Key);
1357

    
1358
            }
1359
            else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol))
1360
            {
1361
                Symbol ownerSymbol = ownerObj as Symbol;
1362
                LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId);
1363

    
1364
                targetLMConnector = null;
1365
                double distance = double.MaxValue;
1366

    
1367
                foreach (LMConnector connector in _LMSymbol.Avoid1Connectors)
1368
                {
1369
                    if (connector.get_ItemStatus() == "Active")
1370
                    {
1371
                        dynamic OID = connector.get_GraphicOID();
1372
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1373
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1374
                        int verticesCount = lineStringGeometry.VertexCount;
1375
                        double[] vertices = null;
1376
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1377
                        for (int i = 0; i < verticesCount; i++)
1378
                        {
1379
                            double x = 0;
1380
                            double y = 0;
1381
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1382

    
1383
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1384
                            if (result < distance)
1385
                            {
1386
                                targetLMConnector = connector;
1387
                                distance = result;
1388
                            }
1389
                        }
1390
                    }
1391
                }
1392

    
1393
                foreach (LMConnector connector in _LMSymbol.Avoid2Connectors)
1394
                {
1395
                    if (connector.get_ItemStatus() == "Active")
1396
                    {
1397
                        dynamic OID = connector.get_GraphicOID();
1398
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1399
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1400
                        int verticesCount = lineStringGeometry.VertexCount;
1401
                        double[] vertices = null;
1402
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1403
                        for (int i = 0; i < verticesCount; i++)
1404
                        {
1405
                            double x = 0;
1406
                            double y = 0;
1407
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1408

    
1409
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1410
                            if (result < distance)
1411
                            {
1412
                                targetLMConnector = connector;
1413
                                distance = result;
1414
                            }
1415
                        }
1416
                    }
1417
                }
1418

    
1419
                if (targetLMConnector != null)
1420
                {
1421
                    LMLabelPersist _LmLabelPersist = null;
1422
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1423
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1424
                    if (_LmLabelPersist != null)
1425
                    {
1426
                        _LmLabelPersist.Commit();
1427
                        ReleaseCOMObjects(_LmLabelPersist);
1428
                    }
1429
                    else
1430
                        RetryEndBreakModeling(endBreak, targetLMConnector);
1431
                }
1432
                
1433
                ReleaseCOMObjects(_LMSymbol);
1434
            }
1435

    
1436
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1437
        }
1438

    
1439
        /// <summary>
1440
        /// EndBreak 모델링이 실패시 다시 시도하는 메서드
1441
        /// </summary>
1442
        /// <param name="endBreak"></param>
1443
        /// <param name="targetLMConnector"></param>
1444
        private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector)
1445
        {
1446
            bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength());
1447
            Array array = null;
1448
            LMLabelPersist _LMLabelPersist = null;
1449
            LMConnector _LMConnector = null;
1450
            dynamic OID = targetLMConnector.get_GraphicOID();
1451
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1452
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1453
            int verticesCount = lineStringGeometry.VertexCount;
1454
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1455
            _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym");
1456

    
1457
            if (isZeroLength)
1458
            {
1459
                double[] vertices = null;
1460
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1461
                double x = 0;
1462
                double y = 0;
1463
                lineStringGeometry.GetVertex(1, ref x, ref y);
1464

    
1465
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y);
1466
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y);
1467

    
1468
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1469
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1470

    
1471
                array = new double[] { 0, x, y };
1472
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1473

    
1474
                AutoJoinPipeRun(_LMConnector.ModelItemID);
1475
            }
1476
            else
1477
            {
1478
                List<double[]> vertices = new List<double[]>();
1479
                for (int i = 1; i <= verticesCount; i++)
1480
                {
1481
                    double x = 0;
1482
                    double y = 0;
1483
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1484
                    vertices.Add(new double[] { x, y });
1485
                }
1486

    
1487
                for (int i = 0; i < vertices.Count; i++)
1488
                {
1489
                    double[] points = vertices[i];
1490
                    if (i == 0)
1491
                    {
1492
                        if (targetLMConnector.ConnectItem1SymbolObject != null)
1493
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1494
                        else
1495
                            placeRunInputs.AddPoint(points[0], points[1]);
1496
                    }
1497
                    else if (i == vertices.Count - 1)
1498
                    {
1499
                        if (targetLMConnector.ConnectItem2SymbolObject != null)
1500
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1501
                        else
1502
                            placeRunInputs.AddPoint(points[0], points[1]);
1503
                    }
1504
                    else
1505
                        placeRunInputs.AddPoint(points[0], points[1]);
1506
                }
1507

    
1508
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID);
1509
                
1510
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1511
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1512

    
1513
                array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1514
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1515

    
1516
                AutoJoinPipeRun(_LMConnector.ModelItemID);
1517
                foreach (var line in lines)
1518
                    line.SPPID.ModelItemId = _LMConnector.ModelItemID;
1519
            }
1520

    
1521

    
1522
            if (_LMLabelPersist != null)
1523
            {
1524
                _LMLabelPersist.Commit();
1525
                ReleaseCOMObjects(_LMLabelPersist);
1526
            }
1527
            else
1528
            {
1529
                
1530
            }
1531

    
1532
            ReleaseCOMObjects(_LMConnector);
1533
            ReleaseCOMObjects(placeRunInputs);
1534
            ReleaseCOMObjects(_LMAItem);
1535
        }
1536

    
1537
        /// <summary>
1538
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
1539
        /// </summary>
1540
        /// <param name="fromModelItemId"></param>
1541
        /// <param name="toModelItemId"></param>
1542
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
1543
        {
1544
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
1545
            _LMAItem item1 = modelItem1.AsLMAItem();
1546
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
1547
            _LMAItem item2 = modelItem2.AsLMAItem();
1548
            
1549
            // item2가 item1으로 조인
1550
            try
1551
            {
1552
                _placement.PIDJoinRuns(ref item1, ref item2);
1553
                item1.Commit();
1554
                item2.Commit();
1555

    
1556
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
1557
                foreach (var line in lines)
1558
                    line.SPPID.ModelItemId = toModelItemId;
1559
            }
1560
            catch (Exception ex)
1561
            {
1562
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1563
            }
1564
            finally
1565
            {
1566
                ReleaseCOMObjects(modelItem1);
1567
                ReleaseCOMObjects(item1);
1568
                ReleaseCOMObjects(modelItem2);
1569
                ReleaseCOMObjects(item2);
1570
            }
1571
        }
1572

    
1573
        /// <summary>
1574
        /// PipeRun을 자동으로 Join하는 메서드
1575
        /// </summary>
1576
        /// <param name="modelItemId"></param>
1577
        private void AutoJoinPipeRun(string modelItemId)
1578
        {
1579
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
1580
            _LMAItem item = modelItem.AsLMAItem();
1581
            try
1582
            {
1583
                string modelitemID = item.Id;
1584
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
1585
                string afterModelItemID = item.Id;
1586
                
1587
                if (modelitemID != afterModelItemID)
1588
                {
1589
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
1590
                    foreach (var line in lines)
1591
                        line.SPPID.ModelItemId = afterModelItemID;
1592
                }
1593
                item.Commit();
1594
            }
1595
            catch (Exception ex)
1596
            {
1597
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1598
            }
1599
            finally
1600
            {
1601
                ReleaseCOMObjects(modelItem);
1602
                ReleaseCOMObjects(item);
1603
            }
1604
        }
1605

    
1606
        /// <summary>
1607
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
1608
        /// </summary>
1609
        /// <param name="run"></param>
1610
        private void JoinRunLine(LineRun run)
1611
        {
1612
            string modelItemId = string.Empty;
1613
            foreach (var item in run.RUNITEMS)
1614
            {
1615
                if (item.GetType() == typeof(Line))
1616
                {
1617
                    Line line = item as Line;
1618
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
1619
                    modelItemId = line.SPPID.ModelItemId;
1620

    
1621
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1622
                }
1623
            }
1624
        }
1625

    
1626
        /// <summary>
1627
        /// PipeRun의 좌표를 가져오는 메서드
1628
        /// </summary>
1629
        /// <param name="modelId"></param>
1630
        /// <returns></returns>
1631
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
1632
        {
1633
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
1634
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
1635

    
1636
            if (modelItem != null)
1637
            {
1638
                foreach (LMRepresentation rep in modelItem.Representations)
1639
                {
1640
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1641
                    {
1642
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1643
                        connectorVertices.Add(_LMConnector, new List<double[]>());
1644
                        dynamic OID = rep.get_GraphicOID();
1645
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1646
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1647
                        int verticesCount = lineStringGeometry.VertexCount;
1648
                        double[] vertices = null;
1649
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1650
                        for (int i = 0; i < verticesCount; i++)
1651
                        {
1652
                            double x = 0;
1653
                            double y = 0;
1654
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1655
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
1656
                        }
1657
                    }
1658
                }
1659

    
1660
                ReleaseCOMObjects(modelItem);
1661
            }
1662

    
1663
            return connectorVertices;
1664
        }
1665

    
1666
        /// <summary>
1667
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함
1668
        /// </summary>
1669
        /// <param name="connectorVertices"></param>
1670
        /// <param name="connX"></param>
1671
        /// <param name="connY"></param>
1672
        /// <param name="x2"></param>
1673
        /// <param name="y2"></param>
1674
        /// <returns></returns>
1675
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
1676
        {
1677
            double length = double.MaxValue;
1678
            LMConnector targetConnector = null;
1679
            foreach (var item in connectorVertices)
1680
            {
1681
                List<double[]> points = item.Value;
1682
                for (int i = 0; i < points.Count - 1; i++)
1683
                {
1684
                    double[] point1 = points[i];
1685
                    double[] point2 = points[i + 1];
1686

    
1687
                    double maxLineX = Math.Max(point1[0], point2[0]);
1688
                    double minLineX = Math.Min(point1[0], point2[0]);
1689
                    double maxLineY = Math.Max(point1[1], point2[1]);
1690
                    double minLineY = Math.Min(point1[1], point2[1]);
1691

    
1692
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
1693

    
1694
                    // 두직선의 교차점
1695
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
1696
                    if (crossingPoint != null)
1697
                    {
1698
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
1699
                        if (length >= distance)
1700
                        {
1701
                            if (slope == SlopeType.Slope &&
1702
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
1703
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1704
                            {
1705
                                targetConnector = item.Key;
1706
                                length = distance;
1707
                            }
1708
                            else if (slope == SlopeType.HORIZONTAL &&
1709
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
1710
                            {
1711
                                targetConnector = item.Key;
1712
                                length = distance;
1713
                            }
1714
                            else if (slope == SlopeType.VERTICAL &&
1715
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1716
                            {
1717
                                targetConnector = item.Key;
1718
                                length = distance;
1719
                            }
1720
                        }
1721
                    }
1722
                }
1723

    
1724

    
1725
            }
1726

    
1727
            if (targetConnector == null)
1728
            {
1729
                foreach (var item in connectorVertices)
1730
                {
1731
                    List<double[]> points = item.Value;
1732
                    foreach (var point in points)
1733
                    {
1734
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
1735
                        if (length >= distance)
1736
                        {
1737
                            targetConnector = item.Key;
1738
                            length = distance;
1739
                        }
1740
                    }
1741
                }
1742

    
1743
            }
1744

    
1745
            return targetConnector;
1746
        }
1747

    
1748
        /// <summary>
1749
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순)
1750
        /// </summary>
1751
        /// <param name="connectorVertices"></param>
1752
        /// <param name="connX"></param>
1753
        /// <param name="connY"></param>
1754
        /// <returns></returns>
1755
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1756
        {
1757
            double length = double.MaxValue;
1758
            LMConnector targetConnector = null;
1759
            foreach (var item in connectorVertices)
1760
            {
1761
                List<double[]> points = item.Value;
1762

    
1763
                foreach (double[] point in points)
1764
                {
1765
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1766
                    if (length >= distance)
1767
                    {
1768
                        targetConnector = item.Key;
1769
                        length = distance;
1770
                    }
1771
                }
1772
            }
1773

    
1774
            return targetConnector;
1775
        }
1776

    
1777
        /// <summary>
1778
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
1779
        /// </summary>
1780
        /// <param name="connectorVertices"></param>
1781
        /// <param name="connX"></param>
1782
        /// <param name="connY"></param>
1783
        /// <returns></returns>
1784
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1785
        {
1786
            double length = double.MaxValue;
1787
            LMConnector targetConnector = null;
1788
            foreach (var item in connectorVertices)
1789
            {
1790
                List<double[]> points = item.Value;
1791
                for (int i = 0; i < points.Count - 1; i++)
1792
                {
1793
                    double[] point1 = points[i];
1794
                    double[] point2 = points[i + 1];
1795
                    double x1 = Math.Min(point1[0], point2[0]);
1796
                    double y1 = Math.Min(point1[1], point2[1]);
1797
                    double x2 = Math.Max(point1[0], point2[0]);
1798
                    double y2 = Math.Max(point1[1], point2[1]);
1799

    
1800
                    if ((x1 <= connX && x2 >= connX) ||
1801
                        (y1 <= connY && y2 >= connY))
1802
                    {
1803
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
1804
                        if (length >= distance)
1805
                        {
1806
                            targetConnector = item.Key;
1807
                            length = distance;
1808
                        }
1809

    
1810
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
1811
                        if (length >= distance)
1812
                        {
1813
                            targetConnector = item.Key;
1814
                            length = distance;
1815
                        }
1816
                    }
1817
                }
1818
            }
1819

    
1820
            // 못찾았을때.
1821
            length = double.MaxValue;
1822
            if (targetConnector == null)
1823
            {
1824
                foreach (var item in connectorVertices)
1825
                {
1826
                    List<double[]> points = item.Value;
1827

    
1828
                    foreach (double[] point in points)
1829
                    {
1830
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1831
                        if (length >= distance)
1832
                        {
1833
                            targetConnector = item.Key;
1834
                            length = distance;
1835
                        }
1836
                    }
1837
                }
1838
            }
1839

    
1840
            return targetConnector;
1841
        }
1842

    
1843
        /// <summary>
1844
        /// Line Number Symbol을 실제로 Modeling하는 메서드
1845
        /// </summary>
1846
        /// <param name="lineNumber"></param>
1847
        private void LineNumberModeling(LineNumber lineNumber)
1848
        {
1849
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1850
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
1851
            LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
1852
            if (connectedLMConnector != null)
1853
            {
1854
                double x = 0;
1855
                double y = 0;
1856
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
1857

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

    
1861
                foreach (var item in connectorVertices)
1862
                    ReleaseCOMObjects(item.Key);
1863
                if (_LmLabelPresist != null)
1864
                {
1865
                    _LmLabelPresist.Commit();
1866
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1867
                    ReleaseCOMObjects(_LmLabelPresist);
1868
                }
1869
                else
1870
                {
1871

    
1872
                }
1873
            }
1874

    
1875
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1876
        }
1877

    
1878
        /// <summary>
1879
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
1880
        /// </summary>
1881
        /// <param name="lineNumber"></param>
1882
        private void InputLineNumberAttribute(LineNumber lineNumber)
1883
        {
1884
            foreach (LineRun run in lineNumber.RUNS)
1885
            {
1886
                foreach (var item in run.RUNITEMS)
1887
                {
1888
                    if (item.GetType() == typeof(Symbol))
1889
                    {
1890
                        Symbol symbol = item as Symbol;
1891
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1892
                        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1893

    
1894
                        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
1895
                        {
1896
                            foreach (var attribute in lineNumber.ATTRIBUTES)
1897
                            {
1898
                                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1899
                                if (mapping != null)
1900
                                {
1901
                                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1902
                                    if (_LMAAttribute != null)
1903
                                    {
1904
                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1905
                                            _LMAAttribute.set_Value(attribute.VALUE);
1906
                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
1907
                                            _LMAAttribute.set_Value(attribute.VALUE);
1908
                                    }
1909
                                }
1910
                            }
1911
                            _LMModelItem.Commit();
1912
                        }
1913
                        if (_LMModelItem != null)
1914
                            ReleaseCOMObjects(_LMModelItem);
1915
                        if (_LMSymbol != null)
1916
                            ReleaseCOMObjects(_LMSymbol);
1917
                    }
1918
                    else if (item.GetType() == typeof(Line))
1919
                    {
1920
                        Line line = item as Line;
1921
                        if (line != null)
1922
                        {
1923
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1924
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
1925
                            {
1926
                                foreach (var attribute in lineNumber.ATTRIBUTES)
1927
                                {
1928
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1929
                                    if (mapping != null)
1930
                                    {
1931
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1932
                                        if (_LMAAttribute != null)
1933
                                        {
1934
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1935
                                                _LMAAttribute.set_Value(attribute.VALUE);
1936
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
1937
                                                _LMAAttribute.set_Value(attribute.VALUE);
1938
                                            
1939
                                        }
1940
                                    }
1941
                                }
1942
                                _LMModelItem.Commit();
1943
                            }
1944
                            if (_LMModelItem != null)
1945
                                ReleaseCOMObjects(_LMModelItem);
1946
                        }
1947
                    }
1948
                }
1949
            }
1950

    
1951
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1952
        }
1953

    
1954
        /// <summary>
1955
        /// Symbol Attribute 입력 메서드
1956
        /// </summary>
1957
        /// <param name="item"></param>
1958
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
1959
        {
1960
            try
1961
            {
1962
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
1963
                string sRep = null;
1964
                if (targetItem.GetType() == typeof(Symbol))
1965
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1966
                else if (targetItem.GetType() == typeof(Equipment))
1967
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1968
                    
1969
                if (!string.IsNullOrEmpty(sRep))
1970
                {
1971
                    LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
1972
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1973
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
1974

    
1975
                    foreach (var item in targetAttributes)
1976
                    {
1977
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1978
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
1979
                        {
1980
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1981
                            if (_Attribute != null)
1982
                                _Attribute.set_Value(item.VALUE);
1983
                        }
1984
                    }
1985
                    _LMModelItem.Commit();
1986
                    
1987
                    ReleaseCOMObjects(_Attributes);
1988
                    ReleaseCOMObjects(_LMModelItem);
1989
                    ReleaseCOMObjects(_LMSymbol);
1990
                }
1991
            }
1992
            catch (Exception ex)
1993
            {
1994
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1995
            }
1996

    
1997
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1998
        }
1999

    
2000
        /// <summary>
2001
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
2002
        /// </summary>
2003
        /// <param name="text"></param>
2004
        private void TextModeling(Text text)
2005
        {
2006
            LMSymbol _LMSymbol = null;
2007
            try
2008
            {
2009
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
2010
                if (text.ASSOCIATION)
2011
                {
2012
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
2013
                    if (owner.GetType() == typeof(Symbol))
2014
                    {
2015
                        Symbol symbol = owner as Symbol;
2016
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2017
                        if (_LMSymbol != null)
2018
                        {
2019
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
2020
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
2021
                            AttributeMapping mapping = null;
2022
                            foreach (var attribute in attributes)
2023
                            {
2024
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
2025
                                    continue;
2026

    
2027
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
2028
                                if (mapping != null)
2029
                                    break;  
2030
                            }
2031

    
2032
                            if (mapping != null)
2033
                            {
2034
                                double x = 0;
2035
                                double y = 0;
2036

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

    
2040
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2041
                                if (_LMLabelPersist!=null)
2042
                                {
2043
                                    _LMLabelPersist.Commit();
2044
                                    ReleaseCOMObjects(_LMLabelPersist);
2045
                                }
2046
                            }
2047
                        }
2048
                    }
2049
                    else if (owner.GetType() == typeof(Line))
2050
                    {
2051

    
2052
                    }
2053
                }
2054
                else
2055
                {
2056
                    LMItemNote _LMItemNote = null;
2057
                    LMAAttribute _LMAAttribute = null;
2058

    
2059
                    double x = 0;
2060
                    double y = 0;
2061

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

    
2064
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
2065
                    _LMSymbol.Commit();
2066
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
2067
                    _LMItemNote.Commit();
2068
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
2069
                    _LMAAttribute.set_Value(text.VALUE);
2070
                    _LMItemNote.Commit();
2071

    
2072
                    if (_LMAAttribute != null)
2073
                        ReleaseCOMObjects(_LMAAttribute);
2074
                    if (_LMItemNote != null)
2075
                        ReleaseCOMObjects(_LMItemNote);
2076
                }
2077
            }
2078
            catch (Exception ex)
2079
            {
2080

    
2081
            }
2082
            finally
2083
            {
2084
                if (_LMSymbol != null)
2085
                    ReleaseCOMObjects(_LMSymbol);
2086
            }
2087

    
2088
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2089
        }
2090

    
2091
        /// <summary>
2092
        /// Note Modeling
2093
        /// </summary>
2094
        /// <param name="note"></param>
2095
        private void NoteModeling(Note note)
2096
        {
2097
            LMSymbol _LMSymbol = null;
2098
            LMItemNote _LMItemNote = null;
2099
            LMAAttribute _LMAAttribute = null;
2100

    
2101
            try
2102
            {
2103
                double x = 0;
2104
                double y = 0;
2105

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

    
2108
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
2109
                _LMSymbol.Commit();
2110
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
2111
                _LMItemNote.Commit();
2112
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
2113
                _LMAAttribute.set_Value(note.VALUE);
2114
                _LMItemNote.Commit();
2115
            }
2116
            catch (Exception ex)
2117
            {
2118

    
2119
            }
2120
            finally
2121
            {
2122
                if (_LMAAttribute != null)
2123
                    ReleaseCOMObjects(_LMAAttribute);
2124
                if (_LMItemNote != null)
2125
                    ReleaseCOMObjects(_LMItemNote);
2126
                if (_LMSymbol != null)
2127
                    ReleaseCOMObjects(_LMSymbol);
2128
            }
2129

    
2130
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2131
        }
2132

    
2133
        /// <summary>
2134
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
2135
        /// </summary>
2136
        /// <param name="x"></param>
2137
        /// <param name="y"></param>
2138
        /// <param name="originX"></param>
2139
        /// <param name="originY"></param>
2140
        /// <param name="SPPIDLabelLocation"></param>
2141
        /// <param name="location"></param>
2142
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
2143
        {
2144
            if (location == Location.None)
2145
            {
2146
                x = originX;
2147
                y = originY;
2148
            }
2149
            else
2150
            {
2151
                if (location.HasFlag(Location.Center))
2152
                {
2153
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
2154
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
2155
                }
2156

    
2157
                if (location.HasFlag(Location.Left))
2158
                    x = SPPIDLabelLocation.X1;
2159
                else if (location.HasFlag(Location.Right))
2160
                    x = SPPIDLabelLocation.X2;
2161

    
2162
                if (location.HasFlag(Location.Down))
2163
                    y = SPPIDLabelLocation.Y1;
2164
                else if (location.HasFlag(Location.Up))
2165
                    y = SPPIDLabelLocation.Y2;
2166
            }
2167
        }
2168

    
2169
        /// <summary>
2170
        /// ComObject를 Release
2171
        /// </summary>
2172
        /// <param name="objVars"></param>
2173
        public void ReleaseCOMObjects(params object[] objVars)
2174
        {
2175
            int intNewRefCount = 0;
2176
            foreach (object obj in objVars)
2177
            {
2178
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
2179
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
2180
            }
2181
        }
2182
    }
2183
}
클립보드 이미지 추가 (최대 크기: 500 MB)