프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 5a83fda2

이력 | 보기 | 이력해설 | 다운로드 (72.2 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
namespace Converter.SPPID
25
{
26
    public class AutoModeling
27
    {
28
        Placement _placement;
29
        LMADataSource dataSource;
30
        Ingr.RAD2D.Application radApp;
31
        SPPID_Document document;
32
        ETCSetting _ETCSetting;
33

    
34
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
35
        public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp)
36
        {
37
            this.document = document;
38
            this.radApp = radApp;
39
            this._ETCSetting = ETCSetting.GetInstance();
40
        }
41

    
42
        public void Run()
43
        {
44
            _placement = new Placement();
45
            dataSource = _placement.PIDDataSource;
46

    
47
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
48
            //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
49
            //application.ActiveWindow.Fit();
50
            //Thread.Sleep(100);
51
            //application.ActiveWindow.Zoom = 60;
52
            //Thread.Sleep(100);
53

    
54
            try
55
            {
56
                // Equipment Modeling
57
                foreach (Equipment equipment in document.Equipments)
58
                    EquipmentModeling(equipment);
59
                
60
                // LineRun Symbol Modeling
61
                foreach (LineNumber lineNumber in document.LINENUMBERS)
62
                    foreach (LineRun run in lineNumber.RUNS)
63
                        SymbolModelingByRun(run);
64
                
65
                // TrimLineRun Symbol Modeling
66
                foreach (TrimLine trimLine in document.TRIMLINES)
67
                    foreach (LineRun run in trimLine.RUNS)
68
                        SymbolModelingByRun(run);
69
                
70
                // LineRun Line Modeling
71
                foreach (LineNumber lineNumber in document.LINENUMBERS)
72
                    foreach (LineRun run in lineNumber.RUNS)
73
                        LineModelingByRun(run);
74
                
75
                // TrimLineRun Line Modeling
76
                foreach (TrimLine trimLine in document.TRIMLINES)
77
                    foreach (LineRun run in trimLine.RUNS)
78
                        LineModelingByRun(run);
79
                
80
                // Branch Line Modeling
81
                foreach (var item in BranchLines)
82
                    BranchLineModeling(item);
83
                
84
                // EndBreak Modeling
85
                foreach (var item in document.EndBreaks)
86
                    EndBreakModeling(item);
87
                
88
                // LineNumber Modeling
89
                foreach (var item in document.LINENUMBERS)
90
                    LineNumberModeling(item);
91

    
92
                // LineRun Line Join
93
                foreach (LineNumber lineNumber in document.LINENUMBERS)
94
                    foreach (LineRun run in lineNumber.RUNS)
95
                        JoinRunLine(run);
96

    
97
                // TrimLineRun Line Join
98
                foreach (TrimLine trimLine in document.TRIMLINES)
99
                    foreach (LineRun run in trimLine.RUNS)
100
                        JoinRunLine(run);
101

    
102
                // Note Modeling
103
                foreach (var item in document.NOTES)
104
                    NoteModeling(item);
105

    
106
                // Text Modeling
107
                foreach (var item in document.TEXTINFOS)
108
                    TextModeling(item);
109

    
110
                // Input LineNumber Attribute
111
                foreach (var item in document.LINENUMBERS)
112
                    InputLineNumberAttribute(item);
113

    
114
                // Input Symbol Attribute
115
                foreach (var item in document.SYMBOLS)
116
                    InputSymbolAttribute(item);
117

    
118
                #region 임시 Label
119
                foreach (var item in document.SYMBOLS)
120
                {
121
                    if (item.SPPID.MAPPINGNAME.Contains("Labels - "))
122
                    {
123
                        SPPIDSymbolInfo info = item.SPPID;
124
                        Array points = new double[] { 0, item.SPPID.ORIGINAL_X, item.SPPID.ORIGINAL_Y };
125
                        BaseModel.Attribute itemAttribute = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
126
                        if (itemAttribute == null)
127
                            continue;
128
                        string symbolUID = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL").VALUE;
129
                        object objectItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
130
                        if (objectItem != null)
131
                        {
132

    
133
                            string sRep = null;
134
                            if (objectItem.GetType() == typeof(Symbol))
135
                                sRep = ((Symbol)objectItem).SPPID.RepresentationId;
136
                            else if (objectItem.GetType() == typeof(Equipment))
137
                                sRep = ((Equipment)objectItem).SPPID.RepresentationId;
138

    
139
                            if (!string.IsNullOrEmpty(sRep))
140
                            {
141
                                LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
142
                                LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(item.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: true);
143
                                LMModelItem _LMModelItem = _TargetItem.ModelItemObject;
144
                                LMAAttributes _Attributes = _LMModelItem.Attributes;
145

    
146
                                foreach (var attribute in item.ATTRIBUTES)
147
                                {
148
                                    if (!string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
149
                                    {
150
                                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
151
                                        if (mapping != null)
152
                                        {
153
                                            LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
154
                                            if (mapping.SPPIDATTRIBUTENAME.Contains("Description"))
155
                                            {
156
                                                if (!DBNull.Value.Equals(_LMAAttribute.get_Value()) && !string.IsNullOrEmpty(_LMAAttribute.get_Value()))
157
                                                {
158
                                                    string value = _LMAAttribute.get_Value() + "\n" + attribute.VALUE;
159
                                                    _LMAAttribute.set_Value(value);
160
                                                }
161
                                                else
162
                                                {
163
                                                    _LMAAttribute.set_Value(attribute.VALUE);
164
                                                }
165
                                            }
166
                                            else if (_LMAAttribute != null)
167
                                                _LMAAttribute.set_Value(attribute.VALUE);
168
                                        }
169
                                    }
170
                                }
171

    
172
                                
173

    
174
                                _LMModelItem.Commit();
175
                                _LMLabelPresist.Commit();
176
                                ReleaseCOMObjects(_TargetItem);
177
                                ReleaseCOMObjects(_LMLabelPresist);
178
                                ReleaseCOMObjects(_LMModelItem);
179
                                ReleaseCOMObjects(_Attributes);
180
                            }
181
                        }
182
                    }
183
                }
184
                #endregion
185
            }
186
            catch (Exception ex)
187
            {
188
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
189
            }
190
            finally
191
            {
192
                ReleaseCOMObjects(dataSource);
193
                ReleaseCOMObjects(_placement);
194
            }
195

    
196
            //System.Windows.Forms.MessageBox.Show("end");
197
        }
198

    
199
        private void LineModelingByRun(LineRun run)
200
        {
201
            Line prevLine = null;
202
            List<Line> lines = new List<Line>();
203
            foreach (var item in run.RUNITEMS)
204
            {
205
                // Line일 경우
206
                if (item.GetType() == typeof(Line))
207
                {
208
                    Line line = item as Line;
209
                    if (prevLine == null)
210
                        lines.Add(line);
211
                    else if (prevLine != null)
212
                    {
213
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
214
                            lines.Add(line);
215
                        else
216
                        {
217
                            if (lines.Count > 0)
218
                            {
219
                                LineModeling(lines);
220
                                lines.Clear();
221
                            }
222
                            lines.Add(line);
223
                        }
224
                    }
225

    
226
                    prevLine = line;
227
                }
228
                // Symbol 일 경우
229
                else if (item.GetType() == typeof(Symbol))
230
                {
231
                    if (lines.Count > 0)
232
                    {
233
                        LineModeling(lines);
234
                        lines.Clear();
235
                    }
236
                }
237
            }
238

    
239
            if (lines.Count > 0)
240
                LineModeling(lines);
241
        }
242

    
243
        private void SymbolModelingByRun(LineRun run)
244
        {
245
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
246
            if (run.RUNITEMS.Count > 0)
247
            {
248
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
249
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
250

    
251
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
252
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
253
            }
254

    
255
            Symbol prevSymbol = null;
256
            Symbol targetSymbol = null;
257
            foreach (var item in run.RUNITEMS)
258
            {
259
                if (item.GetType() == typeof(Symbol))
260
                {
261
                    Symbol symbol = item as Symbol;
262
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
263
                    prevSymbol = symbol;
264
                    targetSymbol = symbol;
265
                }
266
                else
267
                {
268
                    targetSymbol = null;
269
                }
270
            }
271
        }
272

    
273
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
274
        {
275
            foreach (var connector in symbol.CONNECTORS)
276
            {
277
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
278
                if (targetItem != null &&
279
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
280
                    !IsSameLineNumber(symbol, targetItem))
281
                {
282
                    SymbolModeling(symbol, targetItem as Symbol, null);
283
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
284
                    {
285
                        object item = run.RUNITEMS[i];
286
                        if (item.GetType() == typeof(Symbol))
287
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
288
                        else
289
                            break;
290
                    }
291
                    break;
292
                }
293
            }
294

    
295

    
296
        }
297

    
298
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
299
        {
300
            foreach (var connector in symbol.CONNECTORS)
301
            {
302
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
303
                if (targetItem != null &&
304
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
305
                    !IsSameLineNumber(symbol, targetItem))
306
                {
307
                    SymbolModeling(symbol, targetItem as Symbol, null);
308
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
309
                    {
310
                        object item = run.RUNITEMS[i];
311
                        if (item.GetType() == typeof(Symbol))
312
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
313
                        else
314
                            break;
315
                    }
316
                    break;
317
                }
318
            }
319
        }
320

    
321
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
322
        {
323
            if (symbol.SPPID.MAPPINGNAME.Contains("Labels - "))
324
                return;
325
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
326
                return;
327

    
328
            LMSymbol _LMSymbol = null;
329

    
330
            string mappingPath = symbol.SPPID.MAPPINGNAME;
331
            double x = symbol.SPPID.ORIGINAL_X;
332
            double y = symbol.SPPID.ORIGINAL_Y;
333
            int mirror = 0;
334
            double angle = symbol.ANGLE;
335

    
336
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
337
            {
338
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
339

    
340
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
341
                double x1 = 0;
342
                double x2 = 0;
343
                double y1 = 0;
344
                double y2 = 0;
345
                symbol2d.Range(out x1, out y1, out x2, out y2);
346

    
347
                if (y2 < y)
348
                    y = y2;
349
                else if (y1 > y)
350
                    y = y1;
351

    
352
                if (x2 < x)
353
                    x = x2;
354
                else if (x1 > x)
355
                    x = x1;
356

    
357
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
358
                ReleaseCOMObjects(_TargetItem);
359
            }
360
            else if (prevSymbol != null)
361
            {
362
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
363
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
364
                double prevX = _PrevSymbol.get_XCoordinate();
365
                double prevY = _PrevSymbol.get_YCoordinate();
366
                if (slopeType == SlopeType.HORIZONTAL)
367
                    y = prevY;
368
                else if (slopeType == SlopeType.VERTICAL)
369
                    x = prevX;
370
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
371
            }
372
            else
373
            {
374
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
375
            }
376

    
377

    
378
            if (_LMSymbol != null)
379
            {
380
                _LMSymbol.Commit();
381
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
382

    
383
                foreach (var item in symbol.ChildSymbols)
384
                    CreateChildSymbol(item, _LMSymbol);
385
            }
386

    
387
            ReleaseCOMObjects(_LMSymbol);
388
        }
389

    
390
        private void EquipmentModeling(Equipment equipment)
391
        {
392
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
393
                return;
394

    
395
            LMSymbol _LMSymbol = null;
396
            LMSymbol targetItem = null;
397
            string mappingPath = equipment.SPPID.MAPPINGNAME;
398
            double x = equipment.SPPID.ORIGINAL_X;
399
            double y = equipment.SPPID.ORIGINAL_Y;
400
            int mirror = 0;
401
            double angle = equipment.ANGLE;
402

    
403
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
404
            if (connector != null)
405
            {
406
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
407
                if (connEquipment != null)
408
                {
409
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
410
                        EquipmentModeling(connEquipment);
411

    
412
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
413
                    {
414
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
415
                        if (targetItem != null)
416
                        {
417
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
418
                        }
419
                        else
420
                        {
421
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
422
                        }
423
                    }
424
                    else
425
                    {
426
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
427
                    }
428
                }
429
                else
430
                {
431
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
432
                }
433
            }
434
            else
435
            {
436
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
437
            }
438

    
439
            if (_LMSymbol != null)
440
            {
441
                _LMSymbol.Commit();
442
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
443
                ReleaseCOMObjects(_LMSymbol);
444
            }
445

    
446
            if (targetItem != null)
447
            {
448
                ReleaseCOMObjects(targetItem);
449
            }
450
            
451
            //if (equipment.CONNECTORS)
452
            //{
453

    
454
            //}
455

    
456
            //if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
457
            //{
458
            //    LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
459
            //    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
460
            //    ReleaseCOMObjects(_TargetItem);
461
            //}
462
            //else if (prevSymbol != null)
463
            //{
464
            //    LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
465
            //    SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
466
            //    double prevX = _PrevSymbol.get_XCoordinate();
467
            //    double prevY = _PrevSymbol.get_YCoordinate();
468
            //    if (slopeType == SlopeType.HORIZONTAL)
469
            //        y = prevY;
470
            //    else if (slopeType == SlopeType.VERTICAL)
471
            //        x = prevX;
472
            //    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
473
            //}
474
            //else
475
            //{
476
            //    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
477
            //}
478

    
479

    
480
            //if (_LMSymbol != null)
481
            //{
482
            //    _LMSymbol.Commit();
483
            //    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
484

    
485
            //    foreach (var item in symbol.ChildSymbols)
486
            //        CreateChildSymbol(item, _LMSymbol);
487
            //}
488

    
489
            ReleaseCOMObjects(_LMSymbol);
490
        }
491

    
492
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
493
        {
494
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
495
            double x1 = 0;
496
            double x2 = 0;
497
            double y1 = 0;
498
            double y2 = 0;
499
            symbol2d.Range(out x1, out y1, out x2, out y2);
500

    
501
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
502
            if (_LMSymbol != null)
503
            {
504
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
505
                foreach (var item in childSymbol.ChildSymbols)
506
                    CreateChildSymbol(item, _LMSymbol);
507
            }
508
            
509

    
510
            ReleaseCOMObjects(_LMSymbol);
511
        }
512

    
513
        private bool IsSameLineNumber(object item, object targetItem)
514
        {
515
            foreach (var lineNumber in document.LINENUMBERS)
516
            {
517
                foreach (var run in lineNumber.RUNS)
518
                {
519
                    foreach (var runItem in run.RUNITEMS)
520
                    {
521
                        if (runItem == item)
522
                        {
523
                            foreach (var findItem in run.RUNITEMS)
524
                            {
525
                                if (findItem == targetItem)
526
                                {
527
                                    return true;
528
                                }
529
                            }
530

    
531
                            return false;
532

    
533
                        }
534
                    }
535
                }
536
            }
537

    
538
            return false;
539
        }
540

    
541
        private void LineModeling(List<Line> lines)
542
        {
543
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
544
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
545
            LMSymbol _LMSymbol1 = null;
546
            LMSymbol _LMSymbol2 = null;
547
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
548
            LMConnector targetConnector1 = null;
549
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
550
            LMConnector targetConnector2 = null;
551

    
552
            Line startBranchLine = null;
553
            Line endBranchLine = null;
554

    
555
            for (int i = 0; i < lines.Count; i++)
556
            {
557
                Line line = lines[i];
558
                if (i == 0 || i + 1 != lines.Count)
559
                {
560
                    // 시작점에 연결된 Symbol 찾기
561
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
562
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
563
                    {
564
                        _LMSymbol1 = GetTargetSymbol(connItem as Symbol, line);
565
                        if (_LMSymbol1 != null)
566
                            placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y);
567
                        else
568
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
569
                    }
570
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
571
                    {
572
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
573
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
574

    
575
                        if (targetConnector1 != null)
576
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
577
                        else
578
                        {
579
                            startBranchLine = connItem as Line;
580
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
581
                        }
582
                    }
583
                    else
584
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
585
                }
586

    
587
                if (i + 1 == lines.Count)
588
                {
589
                    // 끝점에 연결된 Symbol 찾기
590
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
591

    
592
                    if (i != 0)
593
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
594

    
595
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
596
                    {
597
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
598
                        if (_LMSymbol2 != null)
599
                            placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y);
600
                        else
601
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
602
                            
603
                    }
604
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
605
                    {
606
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
607
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
608

    
609
                        if (targetConnector2 != null)
610
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
611
                        else
612
                        {
613
                            endBranchLine = connItem as Line;
614
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
615
                        }
616
                    }
617
                    else
618
                    {
619
                        placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
620
                    }
621
                }
622
            }
623

    
624
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
625

    
626
            if (_lMConnector != null)
627
            {
628
                foreach (var line in lines)
629
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
630
                _lMConnector.Commit();
631
                if (startBranchLine != null || endBranchLine != null)
632
                {
633
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
634
                }
635
            }
636

    
637

    
638
            if (_LMSymbol1 != null)
639
                ReleaseCOMObjects(_LMSymbol1);
640
            if (_LMSymbol2 != null)
641
                ReleaseCOMObjects(_LMSymbol2);
642
            if (targetConnector1 != null)
643
                ReleaseCOMObjects(targetConnector1);
644
            if (targetConnector2 != null)
645
                ReleaseCOMObjects(targetConnector2);
646
            foreach (var item in connectorVertices1)
647
                ReleaseCOMObjects(item.Key);
648
            foreach (var item in connectorVertices2)
649
                ReleaseCOMObjects(item.Key);
650

    
651
            ReleaseCOMObjects(_lMConnector);
652
            ReleaseCOMObjects(placeRunInputs);
653
            ReleaseCOMObjects(_LMAItem);
654
        }
655

    
656
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
657
        {
658
            LMSymbol _LMSymbol = null;
659
            foreach (var connector in symbol.CONNECTORS)
660
            {
661
                if (connector.CONNECTEDITEM == line.UID)
662
                {
663
                    if (connector.Index == 0)
664
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
665
                    else
666
                    {
667
                        ChildSymbol child = null;
668
                        foreach (var childSymbol in symbol.ChildSymbols)
669
                        {
670
                            if (childSymbol.Connectors.Contains(connector))
671
                                child = childSymbol;
672
                            else
673
                                child = GetChildSymbolByConnector(childSymbol, connector);
674

    
675
                            if (child != null)
676
                                break;
677
                        }
678

    
679
                        if (child != null)
680
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
681
                    }
682

    
683
                    break;  
684
                }
685
            }
686

    
687
            return _LMSymbol;
688
        }
689

    
690
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
691
        {
692
            foreach (var childSymbol in item.ChildSymbols)
693
            {
694
                if (childSymbol.Connectors.Contains(connector))
695
                    return childSymbol;
696
                else
697
                    return GetChildSymbolByConnector(childSymbol, connector);
698
            }
699

    
700
            return null;
701
        }
702

    
703
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
704
        {
705
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
706
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
707

    
708
            LMConnector _StartConnector = null;
709
            LMConnector _EndConnector = null;
710
            double lengthStart = double.MaxValue;
711
            double lengthEnd = double.MaxValue;
712
            List<double[]> startPoints = new List<double[]>();
713
            List<double[]> endPoints = new List<double[]>();
714

    
715
            foreach (var item in connectorVertices)
716
            {
717
                foreach (var point in item.Value)
718
                {
719
                    // Start Point가 Branch
720
                    if (branch.Item2 != null)
721
                    {
722
                        Line targetLine = branch.Item2;
723
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
724
                        if (lengthStart > distance)
725
                        {
726
                            _StartConnector = item.Key;
727
                            lengthStart = distance;
728
                            startPoints = item.Value;
729
                        }
730
                    }
731
                    // End Point가 Branch
732
                    if (branch.Item3 != null)
733
                    {
734
                        Line targetLine = branch.Item3;
735
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
736
                        if (lengthEnd > distance)
737
                        {
738
                            _EndConnector = item.Key;
739
                            lengthEnd = distance;
740
                            endPoints = item.Value;
741
                        }
742
                    }
743
                }
744
            }
745
            #region Branch가 양쪽 전부일 때
746
            if (_StartConnector != null && _StartConnector == _EndConnector)
747
            {
748
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
749

    
750
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
751
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
752

    
753
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
754
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
755
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
756
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
757
                   startPoints[startPoints.Count - 1][0],
758
                   startPoints[startPoints.Count - 1][1],
759
                   startPoints[startPoints.Count - 2][0],
760
                   startPoints[startPoints.Count - 2][1]);
761

    
762
                for (int i = 0; i < startPoints.Count; i++)
763
                {
764
                    double[] point = startPoints[i];
765
                    if (i == 0)
766
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
767
                    else if (i == startPoints.Count - 1)
768
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
769
                    else
770
                        placeRunInputs.AddPoint(point[0], point[1]);
771
                }
772

    
773
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
774
                if (_LMConnector != null)
775
                {
776
                    _LMConnector.Commit();
777
                    foreach (var item in lines)
778
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
779
                }
780

    
781
                foreach (var item in startConnectorVertices)
782
                    ReleaseCOMObjects(item.Key);
783
                foreach (var item in endConnectorVertices)
784
                    ReleaseCOMObjects(item.Key);
785
                ReleaseCOMObjects(placeRunInputs);
786
                ReleaseCOMObjects(_LMAItem);
787
                ReleaseCOMObjects(_LMConnector);
788
            }
789
            #endregion
790
            #region 양쪽이 다른 Branch 
791
            else
792
            {
793
                // Branch 시작 Connector
794
                if (_StartConnector != null)
795
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
796

    
797
                // Branch 끝 Connector
798
                if (_EndConnector != null)
799
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
800
            }
801
            #endregion
802

    
803
            if (_StartConnector != null)
804
                ReleaseCOMObjects(_StartConnector);
805
            if (_EndConnector != null)
806
                ReleaseCOMObjects(_EndConnector);
807
            foreach (var item in connectorVertices)
808
                ReleaseCOMObjects(item.Key);
809
        }
810

    
811
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
812
        {
813
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
814
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
815
            LMConnector _SameRunTargetConnector = null;
816
            LMSymbol _SameRunTargetSymbol = null;
817
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
818
            LMConnector _BranchTargetConnector = null;
819
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
820

    
821
            // 같은 Line Run의 Connector 찾기
822
            foreach (var item in connectorVertices)
823
            {
824
                if (item.Key == _Connector)
825
                    continue;
826

    
827
                if (IsStart &&
828
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
829
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
830
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
831
                {
832
                    _SameRunTargetConnector = item.Key;
833
                    break;
834
                }
835
                else if (!IsStart &&
836
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
837
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
838
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
839
                {
840
                    _SameRunTargetConnector = item.Key;
841
                    break;
842
                }
843
            }
844

    
845
            // Branch 반대편이 Symbol
846
            if (_SameRunTargetConnector == null)
847
            {
848
                foreach (var line in lines)
849
                {
850
                    foreach (var connector in line.CONNECTORS)
851
                    {
852
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
853
                        if (symbol != null)
854
                        {
855
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
856
                            break;
857
                        }
858
                    }
859
                }
860
            }
861

    
862
            // 기존 Connector 제거
863
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
864
            
865
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
866
            if (IsStart)
867
            {
868
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
869
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
870
            }
871
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
872
            else
873
            {
874
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
875
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
876
                    points[points.Count - 1][0],
877
                    points[points.Count - 1][1],
878
                    points[points.Count - 2][0],
879
                    points[points.Count - 2][1]);
880
            }
881

    
882
            for (int i = 0; i < points.Count; i++)
883
            {
884
                double[] point = points[i];
885
                if (i == 0)
886
                {
887
                    if (IsStart)
888
                    {
889
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
890
                    }
891
                    else
892
                    {
893
                        if (_SameRunTargetConnector != null)
894
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
895
                        else if (_SameRunTargetSymbol != null)
896
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
897
                        else
898
                            placeRunInputs.AddPoint(point[0], point[1]);
899
                    }
900
                }
901
                else if (i == points.Count - 1)
902
                {
903
                    if (IsStart)
904
                    {
905
                        if (_SameRunTargetConnector != null)
906
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
907
                        else if (_SameRunTargetSymbol != null)
908
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
909
                        else
910
                            placeRunInputs.AddPoint(point[0], point[1]);
911
                    }
912
                    else
913
                    {
914
                        if (_BranchTargetConnector != null)
915
                        {
916
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
917
                        }
918
                    }
919
                }
920
                else
921
                    placeRunInputs.AddPoint(point[0], point[1]);
922
            }
923
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
924
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
925

    
926
            if (_LMConnector != null)
927
            {
928
                if (_SameRunTargetConnector != null)
929
                {
930
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
931
                }
932
                else
933
                {
934
                    foreach (var item in lines)
935
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
936
                }
937

    
938
                _LMConnector.Commit();
939
                ReleaseCOMObjects(_LMConnector);
940
            }
941

    
942
            ReleaseCOMObjects(placeRunInputs);
943
            ReleaseCOMObjects(_LMAItem);
944
            if (_BranchTargetConnector != null)
945
                ReleaseCOMObjects(_BranchTargetConnector);
946
            if (_SameRunTargetConnector != null)
947
                ReleaseCOMObjects(_SameRunTargetConnector);
948
            if (_SameRunTargetSymbol != null)
949
                ReleaseCOMObjects(_SameRunTargetSymbol);
950
            foreach (var item in connectorVertices)
951
                ReleaseCOMObjects(item.Key);
952
            foreach (var item in branchConnectorVertices)
953
                ReleaseCOMObjects(item.Key);
954
        }
955

    
956
        private void EndBreakModeling(EndBreak endBreak)
957
        {
958
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
959
            LMConnector targetLMConnector = null;
960
            if (ownerObj !=null && ownerObj.GetType() == typeof(Line))
961
            {
962
                Line ownerLine = ownerObj as Line;
963
                LMLabelPersist _LmLabelPersist = null;
964
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
965

    
966
                targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
967
                
968
                if (targetLMConnector != null)
969
                {
970
                    //double[] point = connectorVertices[targetLMConnector][connectorVertices[targetLMConnector].Count - 1];
971
                    //Array array = new double[] { 0, point[0], point[1] };
972
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
973
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
974
                }
975

    
976
                if (_LmLabelPersist != null)
977
                {
978
                    _LmLabelPersist.Commit();
979
                    ReleaseCOMObjects(_LmLabelPersist);
980
                }
981
                else
982
                    RetryEndBreakModeling(endBreak, targetLMConnector);
983

    
984
                foreach (var item in connectorVertices)
985
                    ReleaseCOMObjects(item.Key);
986

    
987
            }
988
            else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol))
989
            {
990
                Symbol ownerSymbol = ownerObj as Symbol;
991
                LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId);
992

    
993
                targetLMConnector = null;
994
                double distance = double.MaxValue;
995

    
996
                foreach (LMConnector connector in _LMSymbol.Avoid1Connectors)
997
                {
998
                    if (connector.get_ItemStatus() == "Active")
999
                    {
1000
                        dynamic OID = connector.get_GraphicOID();
1001
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1002
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1003
                        int verticesCount = lineStringGeometry.VertexCount;
1004
                        double[] vertices = null;
1005
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1006
                        for (int i = 0; i < verticesCount; i++)
1007
                        {
1008
                            double x = 0;
1009
                            double y = 0;
1010
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1011

    
1012
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1013
                            if (result < distance)
1014
                            {
1015
                                targetLMConnector = connector;
1016
                                distance = result;
1017
                            }
1018
                        }
1019
                    }
1020
                }
1021

    
1022
                foreach (LMConnector connector in _LMSymbol.Avoid2Connectors)
1023
                {
1024
                    if (connector.get_ItemStatus() == "Active")
1025
                    {
1026
                        dynamic OID = connector.get_GraphicOID();
1027
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1028
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1029
                        int verticesCount = lineStringGeometry.VertexCount;
1030
                        double[] vertices = null;
1031
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1032
                        for (int i = 0; i < verticesCount; i++)
1033
                        {
1034
                            double x = 0;
1035
                            double y = 0;
1036
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1037

    
1038
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1039
                            if (result < distance)
1040
                            {
1041
                                targetLMConnector = connector;
1042
                                distance = result;
1043
                            }
1044
                        }
1045
                    }
1046
                }
1047

    
1048
                if (targetLMConnector != null)
1049
                {
1050
                    LMLabelPersist _LmLabelPersist = null;
1051
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1052
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1053
                    if (_LmLabelPersist != null)
1054
                    {
1055
                        _LmLabelPersist.Commit();
1056
                        ReleaseCOMObjects(_LmLabelPersist);
1057
                    }
1058
                    else
1059
                        RetryEndBreakModeling(endBreak, targetLMConnector);
1060
                }
1061
                
1062
                ReleaseCOMObjects(_LMSymbol);
1063
            }
1064
        }
1065

    
1066
        private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector)
1067
        {
1068
            bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength());
1069
            Array array = null;
1070
            LMLabelPersist _LMLabelPersist = null;
1071
            LMConnector _LMConnector = null;
1072
            dynamic OID = targetLMConnector.get_GraphicOID();
1073
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1074
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1075
            int verticesCount = lineStringGeometry.VertexCount;
1076
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1077
            _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym");
1078

    
1079
            if (isZeroLength)
1080
            {
1081
                double[] vertices = null;
1082
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1083
                double x = 0;
1084
                double y = 0;
1085
                lineStringGeometry.GetVertex(1, ref x, ref y);
1086

    
1087
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y);
1088
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y);
1089

    
1090
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1091
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1092

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

    
1096
                AutoJoinPipeRun(_LMConnector.ModelItemID);
1097
            }
1098
            else
1099
            {
1100
                List<double[]> vertices = new List<double[]>();
1101
                for (int i = 1; i <= verticesCount; i++)
1102
                {
1103
                    double x = 0;
1104
                    double y = 0;
1105
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1106
                    vertices.Add(new double[] { x, y });
1107
                }
1108

    
1109
                for (int i = 0; i < vertices.Count; i++)
1110
                {
1111
                    double[] points = vertices[i];
1112
                    if (i == 0)
1113
                    {
1114
                        if (targetLMConnector.ConnectItem1SymbolObject != null)
1115
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1116
                        else
1117
                            placeRunInputs.AddPoint(points[0], points[1]);
1118
                    }
1119
                    else if (i == vertices.Count - 1)
1120
                    {
1121
                        if (targetLMConnector.ConnectItem2SymbolObject != null)
1122
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1123
                        else
1124
                            placeRunInputs.AddPoint(points[0], points[1]);
1125
                    }
1126
                    else
1127
                        placeRunInputs.AddPoint(points[0], points[1]);
1128
                }
1129

    
1130
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID);
1131
                
1132
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1133
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1134

    
1135
                foreach (var line in lines)
1136
                    line.SPPID.ModelItemId = _LMConnector.ModelItemID;
1137

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

    
1142

    
1143
            if (_LMLabelPersist != null)
1144
            {
1145
                _LMLabelPersist.Commit();
1146
                ReleaseCOMObjects(_LMLabelPersist);
1147
            }
1148
            else
1149
            {
1150
                
1151
            }
1152

    
1153
            ReleaseCOMObjects(_LMConnector);
1154
            ReleaseCOMObjects(placeRunInputs);
1155
            ReleaseCOMObjects(_LMAItem);
1156
        }
1157

    
1158
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
1159
        {
1160
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
1161
            _LMAItem item1 = modelItem1.AsLMAItem();
1162
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
1163
            _LMAItem item2 = modelItem2.AsLMAItem();
1164
            
1165
            // item2가 item1으로 조인
1166
            try
1167
            {
1168
                _placement.PIDJoinRuns(ref item1, ref item2);
1169
                item1.Commit();
1170
                item2.Commit();
1171
            }
1172
            catch (Exception ex)
1173
            {
1174
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1175
            }
1176
            finally
1177
            {
1178
                ReleaseCOMObjects(modelItem1);
1179
                ReleaseCOMObjects(item1);
1180
                ReleaseCOMObjects(modelItem2);
1181
                ReleaseCOMObjects(item2);
1182
            }
1183
        }
1184

    
1185
        private void AutoJoinPipeRun(string modelItemId)
1186
        {
1187
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
1188
            _LMAItem item = modelItem.AsLMAItem();
1189
            try
1190
            {
1191
                string modelitemID = item.Id;
1192
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
1193
                string afterModelItemID = item.Id;
1194
                
1195
                if (modelitemID != afterModelItemID)
1196
                {
1197
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
1198
                    foreach (var line in lines)
1199
                        line.SPPID.ModelItemId = afterModelItemID;
1200
                }
1201
                item.Commit();
1202
            }
1203
            catch (Exception ex)
1204
            {
1205
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1206
            }
1207
            finally
1208
            {
1209
                ReleaseCOMObjects(modelItem);
1210
                ReleaseCOMObjects(item);
1211
            }
1212
        }
1213

    
1214
        private void JoinRunLine(LineRun run)
1215
        {
1216
            string modelItemId = string.Empty;
1217
            foreach (var item in run.RUNITEMS)
1218
            {
1219
                if (item.GetType() == typeof(Line))
1220
                {
1221
                    Line line = item as Line;
1222
                    if (modelItemId != line.SPPID.ModelItemId)
1223
                    {
1224
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
1225
                        modelItemId = line.SPPID.ModelItemId;
1226
                    }
1227
                }
1228
            }
1229
        }
1230

    
1231
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
1232
        {
1233
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
1234
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
1235

    
1236
            if (modelItem != null)
1237
            {
1238
                foreach (LMRepresentation rep in modelItem.Representations)
1239
                {
1240
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1241
                    {
1242
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1243
                        connectorVertices.Add(_LMConnector, new List<double[]>());
1244
                        dynamic OID = rep.get_GraphicOID();
1245
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1246
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1247
                        int verticesCount = lineStringGeometry.VertexCount;
1248
                        double[] vertices = null;
1249
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1250
                        for (int i = 0; i < verticesCount; i++)
1251
                        {
1252
                            double x = 0;
1253
                            double y = 0;
1254
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1255
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
1256
                        }
1257
                    }
1258
                }
1259

    
1260
                ReleaseCOMObjects(modelItem);
1261
            }
1262

    
1263
            return connectorVertices;
1264
        }
1265

    
1266
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
1267
        {
1268
            double length = double.MaxValue;
1269
            LMConnector targetConnector = null;
1270
            foreach (var item in connectorVertices)
1271
            {
1272
                List<double[]> points = item.Value;
1273
                for (int i = 0; i < points.Count - 1; i++)
1274
                {
1275
                    double[] point1 = points[i];
1276
                    double[] point2 = points[i + 1];
1277

    
1278
                    double maxLineX = Math.Max(point1[0], point2[0]);
1279
                    double minLineX = Math.Min(point1[0], point2[0]);
1280
                    double maxLineY = Math.Max(point1[1], point2[1]);
1281
                    double minLineY = Math.Min(point1[1], point2[1]);
1282

    
1283
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
1284

    
1285
                    // 두직선의 교차점
1286
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
1287
                    if (crossingPoint != null)
1288
                    {
1289
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
1290
                        if (length >= distance)
1291
                        {
1292
                            if (slope == SlopeType.Slope &&
1293
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
1294
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1295
                            {
1296
                                targetConnector = item.Key;
1297
                                length = distance;
1298
                            }
1299
                            else if (slope == SlopeType.HORIZONTAL &&
1300
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
1301
                            {
1302
                                targetConnector = item.Key;
1303
                                length = distance;
1304
                            }
1305
                            else if (slope == SlopeType.VERTICAL &&
1306
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1307
                            {
1308
                                targetConnector = item.Key;
1309
                                length = distance;
1310
                            }
1311
                        }
1312
                    }
1313
                }
1314

    
1315

    
1316
            }
1317

    
1318
            if (targetConnector == null)
1319
            {
1320
                foreach (var item in connectorVertices)
1321
                {
1322
                    List<double[]> points = item.Value;
1323
                    foreach (var point in points)
1324
                    {
1325
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
1326
                        if (length >= distance)
1327
                        {
1328
                            targetConnector = item.Key;
1329
                            length = distance;
1330
                        }
1331
                    }
1332
                }
1333

    
1334
            }
1335

    
1336
            return targetConnector;
1337
        }
1338

    
1339
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1340
        {
1341
            double length = double.MaxValue;
1342
            LMConnector targetConnector = null;
1343
            foreach (var item in connectorVertices)
1344
            {
1345
                List<double[]> points = item.Value;
1346

    
1347
                foreach (double[] point in points)
1348
                {
1349
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1350
                    if (length >= distance)
1351
                    {
1352
                        targetConnector = item.Key;
1353
                        length = distance;
1354
                    }
1355
                }
1356
            }
1357

    
1358
            return targetConnector;
1359
        }
1360

    
1361
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1362
        {
1363
            double length = double.MaxValue;
1364
            LMConnector targetConnector = null;
1365
            foreach (var item in connectorVertices)
1366
            {
1367
                List<double[]> points = item.Value;
1368
                for (int i = 0; i < points.Count - 1; i++)
1369
                {
1370
                    double[] point1 = points[i];
1371
                    double[] point2 = points[i + 1];
1372
                    double x1 = Math.Min(point1[0], point2[0]);
1373
                    double y1 = Math.Min(point1[1], point2[1]);
1374
                    double x2 = Math.Max(point1[0], point2[0]);
1375
                    double y2 = Math.Max(point1[1], point2[1]);
1376

    
1377
                    if ((x1 <= connX && x2 >= connX) ||
1378
                        (y1 <= connY && y2 >= connY))
1379
                    {
1380
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
1381
                        if (length >= distance)
1382
                        {
1383
                            targetConnector = item.Key;
1384
                            length = distance;
1385
                        }
1386

    
1387
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
1388
                        if (length >= distance)
1389
                        {
1390
                            targetConnector = item.Key;
1391
                            length = distance;
1392
                        }
1393
                    }
1394
                }
1395
            }
1396

    
1397
            // 못찾았을때.
1398
            length = double.MaxValue;
1399
            if (targetConnector == null)
1400
            {
1401
                foreach (var item in connectorVertices)
1402
                {
1403
                    List<double[]> points = item.Value;
1404

    
1405
                    foreach (double[] point in points)
1406
                    {
1407
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1408
                        if (length >= distance)
1409
                        {
1410
                            targetConnector = item.Key;
1411
                            length = distance;
1412
                        }
1413
                    }
1414
                }
1415
            }
1416

    
1417
            return targetConnector;
1418
        }
1419

    
1420
        private void LineNumberModeling(LineNumber lineNumber)
1421
        {
1422
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1423
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
1424
            LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
1425
            if (connectedLMConnector != null)
1426
            {
1427
                double x = 0;
1428
                double y = 0;
1429
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
1430

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

    
1435
                foreach (var item in connectorVertices)
1436
                    ReleaseCOMObjects(item.Key);
1437
                if (_LmLabelPresist != null)
1438
                {
1439
                    _LmLabelPresist.Commit();
1440
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1441
                    ReleaseCOMObjects(_LmLabelPresist);
1442
                }
1443
                else
1444
                {
1445

    
1446
                }
1447
            }
1448
        }
1449

    
1450
        private void InputLineNumberAttribute(LineNumber lineNumber)
1451
        {
1452
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1453
            if (line != null)
1454
            {
1455
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1456
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
1457
                {
1458
                    foreach (var attribute in lineNumber.ATTRIBUTES)
1459
                    {
1460
                        LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1461
                        if (mapping != null)
1462
                        {
1463
                            LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1464
                            if (_LMAAttribute != null)
1465
                            {
1466
                                if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1467
                                    _LMAAttribute.set_Value(attribute.VALUE);
1468
                                else if (_LMAAttribute.get_Value() != attribute.VALUE)
1469
                                    _LMAAttribute.set_Value(attribute.VALUE);
1470
                                _LMModelItem.Commit();
1471
                            }
1472
                        }
1473
                    }
1474
                }
1475
                ReleaseCOMObjects(_LMModelItem);
1476
            }
1477
        }
1478

    
1479
        private void InputSymbolAttribute(Symbol symbol)
1480
        {
1481
            try
1482
            {
1483
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1484
                {
1485
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1486
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1487
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
1488

    
1489
                    foreach (var item in symbol.PROPERTIES)
1490
                    {
1491

    
1492

    
1493
                    }
1494

    
1495
                    foreach (var item in symbol.ATTRIBUTES)
1496
                    {
1497
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1498
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
1499
                        {
1500
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1501
                            if (_Attribute != null)
1502
                            {
1503
                                // 임시
1504
                                if (item.ATTRIBUTETYPE == "String")
1505
                                {
1506
                                    if (!string.IsNullOrEmpty(item.VALUE))
1507
                                    {
1508
                                        if (!DBNull.Value.Equals(_Attribute.get_Value()) && !string.IsNullOrEmpty(_Attribute.get_Value()))
1509
                                        {
1510
                                            string value = _Attribute.get_Value() + "\n" + item.VALUE;
1511
                                            _Attribute.set_Value(value);
1512
                                        }
1513
                                        else
1514
                                        {
1515
                                            _Attribute.set_Value(item.VALUE);
1516
                                        }
1517
                                    }
1518
                                }
1519
                                else
1520
                                {
1521
                                    _Attribute.set_Value(item.VALUE);
1522
                                }
1523
                            }
1524
                        }
1525
                    }
1526

    
1527
                    foreach (var item in symbol.ASSOCIATIONS)
1528
                    {
1529

    
1530
                    }
1531

    
1532
                    ReleaseCOMObjects(_LMSymbol);
1533
                    ReleaseCOMObjects(_Attributes);
1534
                    ReleaseCOMObjects(_LMModelItem);
1535
                }
1536
            }
1537
            catch (Exception ex)
1538
            {
1539
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1540
            }
1541
        }
1542

    
1543
        private void TextModeling(Text text)
1544
        {
1545
            LMSymbol _LMSymbol = null;
1546
            try
1547
            {
1548
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
1549
                if (text.ASSOCIATION)
1550
                {
1551
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
1552
                    if (owner.GetType() == typeof(Symbol))
1553
                    {
1554
                        Symbol symbol = owner as Symbol;
1555
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1556
                        if (_LMSymbol != null)
1557
                        {
1558
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
1559
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
1560
                            AttributeMapping mapping = null;
1561
                            foreach (var attribute in attributes)
1562
                            {
1563
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
1564
                                    continue;
1565

    
1566
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
1567
                                if (mapping != null)
1568
                                    break;  
1569
                            }
1570

    
1571
                            if (mapping != null)
1572
                            {
1573
                                double x = 0;
1574
                                double y = 0;
1575

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

    
1579
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: true);
1580
                                if (_LMLabelPersist!=null)
1581
                                {
1582
                                    _LMLabelPersist.Commit();
1583
                                    ReleaseCOMObjects(_LMLabelPersist);
1584
                                }
1585
                            }
1586
                        }
1587
                    }
1588
                    else if (owner.GetType() == typeof(Line))
1589
                    {
1590

    
1591
                    }
1592
                }
1593
                else
1594
                {
1595
                    LMItemNote _LMItemNote = null;
1596
                    LMAAttribute _LMAAttribute = null;
1597

    
1598
                    double x = 0;
1599
                    double y = 0;
1600

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

    
1603
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
1604
                    _LMSymbol.Commit();
1605
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1606
                    _LMItemNote.Commit();
1607
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1608
                    _LMAAttribute.set_Value(text.VALUE);
1609
                    _LMItemNote.Commit();
1610

    
1611
                    if (_LMAAttribute != null)
1612
                        ReleaseCOMObjects(_LMAAttribute);
1613
                    if (_LMItemNote != null)
1614
                        ReleaseCOMObjects(_LMItemNote);
1615
                }
1616
            }
1617
            catch (Exception ex)
1618
            {
1619

    
1620
            }
1621
            finally
1622
            {
1623
                if (_LMSymbol != null)
1624
                    ReleaseCOMObjects(_LMSymbol);
1625
            }
1626
        }
1627

    
1628
        private void NoteModeling(Note note)
1629
        {
1630
            LMSymbol _LMSymbol = null;
1631
            LMItemNote _LMItemNote = null;
1632
            LMAAttribute _LMAAttribute = null;
1633

    
1634
            try
1635
            {
1636
                double x = 0;
1637
                double y = 0;
1638

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

    
1641
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
1642
                _LMSymbol.Commit();
1643
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1644
                _LMItemNote.Commit();
1645
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1646
                _LMAAttribute.set_Value(note.VALUE);
1647
                _LMItemNote.Commit();
1648
            }
1649
            catch (Exception ex)
1650
            {
1651

    
1652
            }
1653
            finally
1654
            {
1655
                if (_LMAAttribute != null)
1656
                    ReleaseCOMObjects(_LMAAttribute);
1657
                if (_LMItemNote != null)
1658
                    ReleaseCOMObjects(_LMItemNote);
1659
                if (_LMSymbol != null)
1660
                    ReleaseCOMObjects(_LMSymbol);
1661
            }
1662
            
1663
        }
1664

    
1665
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
1666
        {
1667
            if (location == Location.None)
1668
            {
1669
                x = originX;
1670
                y = originY;
1671
            }
1672
            else
1673
            {
1674
                if (location.HasFlag(Location.Center))
1675
                {
1676
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
1677
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
1678
                }
1679

    
1680
                if (location.HasFlag(Location.Left))
1681
                    x = SPPIDLabelLocation.X1;
1682
                else if (location.HasFlag(Location.Right))
1683
                    x = SPPIDLabelLocation.X2;
1684

    
1685
                if (location.HasFlag(Location.Down))
1686
                    y = SPPIDLabelLocation.Y1;
1687
                else if (location.HasFlag(Location.Up))
1688
                    y = SPPIDLabelLocation.Y2;
1689
            }
1690
        }
1691

    
1692
        public void ReleaseCOMObjects(params object[] objVars)
1693
        {
1694
            int intNewRefCount = 0;
1695
            foreach (object obj in objVars)
1696
            {
1697
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1698
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1699
            }
1700
        }
1701
    }
1702
}
클립보드 이미지 추가 (최대 크기: 500 MB)