프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 310aeb31

이력 | 보기 | 이력해설 | 다운로드 (51.7 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

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

    
40
        public void Run()
41
        {
42
            _placement = new Placement();
43
            dataSource = _placement.PIDDataSource;
44
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
45
            //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
46
            //application.ActiveWindow.Fit();
47
            //Thread.Sleep(100);
48
            //application.ActiveWindow.Zoom = 60;
49
            //Thread.Sleep(100);
50

    
51

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

    
100
                // Note Modeling
101
                foreach (var item in document.NOTES)
102
                    NoteModeling(item);
103
                
104
                // Text Modeling
105
                foreach (var item in document.TEXTINFOS)
106
                    TextModeling(item);
107

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

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

    
116
                #region 임시 Label
117
                foreach (var item in document.SYMBOLS)
118
                {
119
                    if (item.TYPE.Contains("Labels"))
120
                    {
121
                        SPPIDSymbolInfo info = item.SPPID;
122
                        Array points = new double[] { 0, item.SPPID.ORIGINAL_X, item.SPPID.ORIGINAL_Y };
123
                        string symbolUID = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "SYMBOLOWNER").VALUE;
124
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, symbolUID) as Symbol;
125

    
126
                        LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
127
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(item.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: true);
128
                        LMModelItem _LMModelItem = _TargetItem.ModelItemObject;
129
                        LMAAttributes _Attributes = _LMModelItem.Attributes;
130

    
131
                        foreach (var attribute in item.ATTRIBUTES)
132
                        {
133
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
134
                            if (mapping != null)
135
                            {
136
                                LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
137
                                if (_LMAAttribute != null)
138
                                    _LMAAttribute.set_Value(attribute.VALUE);
139
                            }
140
                        }
141
                        _LMModelItem.Commit();
142
                        _LMLabelPresist.Commit();
143
                        ReleaseCOMObjects(_TargetItem);
144
                        ReleaseCOMObjects(_LMLabelPresist);
145
                        ReleaseCOMObjects(_LMModelItem);
146
                        ReleaseCOMObjects(_Attributes);
147
                    }
148
                }
149
                #endregion
150
            }
151
            catch (Exception ex)
152
            {
153
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
154
            }
155
            finally
156
            {
157
                ReleaseCOMObjects(dataSource);
158
                ReleaseCOMObjects(_placement);
159
            }
160

    
161
            //System.Windows.Forms.MessageBox.Show("end");
162
        }
163

    
164
        public void Test()
165
        {
166
            _placement = new Placement();
167
            dataSource = _placement.PIDDataSource;
168

    
169
            DependencyObject drawingObject = radApp.ActiveDocument.SelectSet[0] as DependencyObject;
170
            if (drawingObject != null)
171
            {
172
                string modelitemID = drawingObject.AttributeSets[0][5].GetValue().ToString();
173
                radApp.ActiveDocument.SelectSet.RemoveAll();
174
                LMPipeRun run = dataSource.GetPipeRun(modelitemID);
175
                _LMAItem item = run.AsLMAItem();
176
                string modelitemID2 = item.Id;
177
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
178
                string afterModelItemID = item.Id;
179
                if (modelitemID2 != afterModelItemID)
180
                {
181

    
182
                }
183
            }
184
        }
185

    
186
        private void LineModelingByRun(LineRun run)
187
        {
188
            Line prevLine = null;
189
            List<Line> lines = new List<Line>();
190
            foreach (var item in run.RUNITEMS)
191
            {
192
                // Line일 경우
193
                if (item.GetType() == typeof(Line))
194
                {
195
                    Line line = item as Line;
196
                    if (prevLine == null)
197
                        lines.Add(line);
198
                    else if (prevLine != null)
199
                    {
200
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
201
                            lines.Add(line);
202
                        else
203
                        {
204
                            if (lines.Count > 0)
205
                            {
206
                                LineModeling(lines);
207
                                lines.Clear();
208
                            }
209
                            lines.Add(line);
210
                        }
211
                    }
212

    
213
                    prevLine = line;
214
                }
215
                // Symbol 일 경우
216
                else if (item.GetType() == typeof(Symbol))
217
                {
218
                    if (lines.Count > 0)
219
                    {
220
                        LineModeling(lines);
221
                        lines.Clear();
222
                    }
223
                }
224
            }
225

    
226
            if (lines.Count > 0)
227
                LineModeling(lines);
228
        }
229

    
230
        private void SymbolModelingByRun(LineRun run)
231
        {
232
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
233
            if (run.RUNITEMS.Count > 0)
234
            {
235
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
236
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
237

    
238
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
239
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
240
            }
241

    
242
            Symbol prevSymbol = null;
243
            Symbol targetSymbol = null;
244
            foreach (var item in run.RUNITEMS)
245
            {
246
                if (item.GetType() == typeof(Symbol))
247
                {
248
                    Symbol symbol = item as Symbol;
249
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
250
                    prevSymbol = symbol;
251
                    targetSymbol = symbol;
252
                }
253
                else
254
                {
255
                    targetSymbol = null;
256
                }
257
            }
258
        }
259

    
260
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
261
        {
262
            foreach (var connector in symbol.CONNECTORS)
263
            {
264
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
265
                if (targetItem != null &&
266
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
267
                    !IsSameLineNumber(symbol, targetItem))
268
                {
269
                    SymbolModeling(symbol, targetItem as Symbol, null);
270
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
271
                    {
272
                        object item = run.RUNITEMS[i];
273
                        if (item.GetType() == typeof(Symbol))
274
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
275
                        else
276
                            break;
277
                    }
278
                    break;
279
                }
280
            }
281

    
282

    
283
        }
284

    
285
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
286
        {
287
            foreach (var connector in symbol.CONNECTORS)
288
            {
289
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
290
                if (targetItem != null &&
291
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
292
                    !IsSameLineNumber(symbol, targetItem))
293
                {
294
                    SymbolModeling(symbol, targetItem as Symbol, null);
295
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
296
                    {
297
                        object item = run.RUNITEMS[i];
298
                        if (item.GetType() == typeof(Symbol))
299
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
300
                        else
301
                            break;
302
                    }
303
                    break;
304
                }
305
            }
306
        }
307

    
308
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
309
        {
310
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
311
                return;
312

    
313
            LMSymbol _LMSymbol = null;
314

    
315
            string mappingPath = symbol.SPPID.MAPPINGNAME;
316
            double x = symbol.SPPID.ORIGINAL_X;
317
            double y = symbol.SPPID.ORIGINAL_Y;
318
            int mirror = 0;
319
            double angle = symbol.ANGLE;
320

    
321
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
322
            {
323
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
324
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
325
                ReleaseCOMObjects(_TargetItem);
326
            }
327
            else if (prevSymbol != null)
328
            {
329
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
330
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
331
                double prevX = _PrevSymbol.get_XCoordinate();
332
                double prevY = _PrevSymbol.get_YCoordinate();
333
                if (slopeType == SlopeType.HORIZONTAL)
334
                    y = prevY;
335
                else if (slopeType == SlopeType.VERTICAL)
336
                    x = prevX;
337
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
338
            }
339
            else
340
            {
341
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
342
            }
343

    
344

    
345
            if (_LMSymbol != null)
346
            {
347
                _LMSymbol.Commit();
348
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
349

    
350
                foreach (var item in symbol.ChildSymbols)
351
                    CreateChildSymbol(item, _LMSymbol);
352
            }
353

    
354
            ReleaseCOMObjects(_LMSymbol);
355
        }
356

    
357
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
358
        {
359
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
360
            double x1 = 0;
361
            double x2 = 0;
362
            double y1 = 0;
363
            double y2 = 0;
364
            symbol2d.Range(out x1, out y1, out x2, out y2);
365

    
366
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
367
            if (_LMSymbol != null)
368
            {
369
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
370
                foreach (var item in childSymbol.ChildSymbols)
371
                    CreateChildSymbol(item, _LMSymbol);
372
            }
373
            
374

    
375
            ReleaseCOMObjects(_LMSymbol);
376
        }
377

    
378
        private bool IsSameLineNumber(object item, object targetItem)
379
        {
380
            foreach (var lineNumber in document.LINENUMBERS)
381
            {
382
                foreach (var run in lineNumber.RUNS)
383
                {
384
                    foreach (var runItem in run.RUNITEMS)
385
                    {
386
                        if (runItem == item)
387
                        {
388
                            foreach (var findItem in run.RUNITEMS)
389
                            {
390
                                if (findItem == targetItem)
391
                                {
392
                                    return true;
393
                                }
394
                            }
395

    
396
                            return false;
397

    
398
                        }
399
                    }
400
                }
401
            }
402

    
403
            return false;
404
        }
405

    
406
        private void LineModeling(List<Line> lines)
407
        {
408
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
409
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
410
            LMSymbol _LMSymbol1 = null;
411
            LMSymbol _LMSymbol2 = null;
412
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
413
            LMConnector targetConnector1 = null;
414
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
415
            LMConnector targetConnector2 = null;
416

    
417
            Line startBranchLine = null;
418
            Line endBranchLine = null;
419

    
420
            for (int i = 0; i < lines.Count; i++)
421
            {
422
                Line line = lines[i];
423
                if (i == 0 || i + 1 != lines.Count)
424
                {
425
                    // 시작점에 연결된 Symbol 찾기
426
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
427
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
428
                    {
429
                        _LMSymbol1 = GetTargetSymbol(connItem as Symbol, line);
430
                        if (_LMSymbol1 != null)
431
                            placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y);
432
                        else
433
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
434
                    }
435
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
436
                    {
437
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
438
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
439

    
440
                        if (targetConnector1 != null)
441
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
442
                        else
443
                        {
444
                            startBranchLine = connItem as Line;
445
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
446
                        }
447
                    }
448
                    else
449
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
450
                }
451

    
452
                if (i + 1 == lines.Count)
453
                {
454
                    // 끝점에 연결된 Symbol 찾기
455
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
456

    
457
                    if (i != 0)
458
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
459

    
460
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
461
                    {
462
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
463
                        if (_LMSymbol2 != null)
464
                            placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y);
465
                        else
466
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
467
                            
468
                    }
469
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
470
                    {
471
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
472
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
473

    
474
                        if (targetConnector2 != null)
475
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
476
                        else
477
                        {
478
                            endBranchLine = connItem as Line;
479
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
480
                        }
481
                    }
482
                    else
483
                    {
484
                        placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
485
                    }
486
                }
487
            }
488

    
489
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
490

    
491
            if (_lMConnector != null)
492
            {
493
                foreach (var line in lines)
494
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
495
                _lMConnector.Commit();
496
                if (startBranchLine != null || endBranchLine != null)
497
                {
498
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
499
                }
500
            }
501

    
502

    
503
            if (_LMSymbol1 != null)
504
                ReleaseCOMObjects(_LMSymbol1);
505
            if (_LMSymbol2 != null)
506
                ReleaseCOMObjects(_LMSymbol2);
507
            if (targetConnector1 != null)
508
                ReleaseCOMObjects(targetConnector1);
509
            if (targetConnector2 != null)
510
                ReleaseCOMObjects(targetConnector2);
511
            foreach (var item in connectorVertices1)
512
                ReleaseCOMObjects(item.Key);
513
            foreach (var item in connectorVertices2)
514
                ReleaseCOMObjects(item.Key);
515

    
516
            ReleaseCOMObjects(_lMConnector);
517
            ReleaseCOMObjects(placeRunInputs);
518
            ReleaseCOMObjects(_LMAItem);
519
        }
520

    
521
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
522
        {
523
            LMSymbol _LMSymbol = null;
524
            foreach (var connector in symbol.CONNECTORS)
525
            {
526
                if (connector.CONNECTEDITEM == line.UID)
527
                {
528
                    if (connector.Index == 0)
529
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
530
                    else
531
                    {
532
                        ChildSymbol child = null;
533
                        foreach (var childSymbol in symbol.ChildSymbols)
534
                        {
535
                            if (childSymbol.Connectors.Contains(connector))
536
                                child = childSymbol;
537
                            else
538
                                child = GetChildSymbolByConnector(childSymbol, connector);
539

    
540
                            if (child != null)
541
                                break;
542
                        }
543

    
544
                        if (child != null)
545
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
546
                    }
547

    
548
                    break;  
549
                }
550
            }
551

    
552
            return _LMSymbol;
553
        }
554

    
555
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
556
        {
557
            foreach (var childSymbol in item.ChildSymbols)
558
            {
559
                if (childSymbol.Connectors.Contains(connector))
560
                    return childSymbol;
561
                else
562
                    return GetChildSymbolByConnector(childSymbol, connector);
563
            }
564

    
565
            return null;
566
        }
567

    
568
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
569
        {
570
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
571
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
572

    
573
            LMConnector _StartConnector = null;
574
            LMConnector _EndConnector = null;
575
            double lengthStart = double.MaxValue;
576
            double lengthEnd = double.MaxValue;
577
            List<double[]> startPoints = new List<double[]>();
578
            List<double[]> endPoints = new List<double[]>();
579

    
580
            foreach (var item in connectorVertices)
581
            {
582
                foreach (var point in item.Value)
583
                {
584
                    // Start Point가 Branch
585
                    if (branch.Item2 != null)
586
                    {
587
                        Line targetLine = branch.Item2;
588
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
589
                        if (lengthStart > distance)
590
                        {
591
                            _StartConnector = item.Key;
592
                            lengthStart = distance;
593
                            startPoints = item.Value;
594
                        }
595
                    }
596
                    // End Point가 Branch
597
                    if (branch.Item3 != null)
598
                    {
599
                        Line targetLine = branch.Item3;
600
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
601
                        if (lengthEnd > distance)
602
                        {
603
                            _EndConnector = item.Key;
604
                            lengthEnd = distance;
605
                            endPoints = item.Value;
606
                        }
607
                    }
608
                }
609
            }
610
            #region Branch가 양쪽 전부일 때
611
            if (_StartConnector != null && _StartConnector == _EndConnector)
612
            {
613
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
614

    
615
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
616
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
617

    
618
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
619
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
620
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
621
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
622
                   startPoints[startPoints.Count - 1][0],
623
                   startPoints[startPoints.Count - 1][1],
624
                   startPoints[startPoints.Count - 2][0],
625
                   startPoints[startPoints.Count - 2][1]);
626

    
627
                for (int i = 0; i < startPoints.Count; i++)
628
                {
629
                    double[] point = startPoints[i];
630
                    if (i == 0)
631
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
632
                    else if (i == startPoints.Count - 1)
633
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
634
                    else
635
                        placeRunInputs.AddPoint(point[0], point[1]);
636
                }
637

    
638
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
639
                if (_LMConnector != null)
640
                {
641
                    _LMConnector.Commit();
642
                    foreach (var item in lines)
643
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
644
                }
645

    
646
                foreach (var item in startConnectorVertices)
647
                    ReleaseCOMObjects(item.Key);
648
                foreach (var item in endConnectorVertices)
649
                    ReleaseCOMObjects(item.Key);
650
                ReleaseCOMObjects(placeRunInputs);
651
                ReleaseCOMObjects(_LMAItem);
652
                ReleaseCOMObjects(_LMConnector);
653
            }
654
            #endregion
655
            #region 양쪽이 다른 Branch 
656
            else
657
            {
658
                // Branch 시작 Connector
659
                if (_StartConnector != null)
660
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
661

    
662
                // Branch 끝 Connector
663
                if (_EndConnector != null)
664
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
665
            }
666
            #endregion
667

    
668
            if (_StartConnector != null)
669
                ReleaseCOMObjects(_StartConnector);
670
            if (_EndConnector != null)
671
                ReleaseCOMObjects(_EndConnector);
672
            foreach (var item in connectorVertices)
673
                ReleaseCOMObjects(item.Key);
674
        }
675

    
676
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
677
        {
678
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
679
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
680
            LMConnector _SameRunTargetConnector = null;
681
            LMSymbol _SameRunTargetSymbol = null;
682
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
683
            LMConnector _BranchTargetConnector = null;
684
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
685

    
686
            // 같은 Line Run의 Connector 찾기
687
            foreach (var item in connectorVertices)
688
            {
689
                if (item.Key == _Connector)
690
                    continue;
691

    
692
                if (IsStart &&
693
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
694
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
695
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
696
                {
697
                    _SameRunTargetConnector = item.Key;
698
                    break;
699
                }
700
                else if (!IsStart &&
701
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
702
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
703
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
704
                {
705
                    _SameRunTargetConnector = item.Key;
706
                    break;
707
                }
708
            }
709

    
710
            // Branch 반대편이 Symbol
711
            if (_SameRunTargetConnector == null)
712
            {
713
                foreach (var line in lines)
714
                {
715
                    foreach (var connector in line.CONNECTORS)
716
                    {
717
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
718
                        if (symbol != null)
719
                        {
720
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
721
                            break;
722
                        }
723
                    }
724
                }
725
            }
726

    
727
            // 기존 Connector 제거
728
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
729
            
730
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
731
            if (IsStart)
732
            {
733
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
734
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
735
            }
736
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
737
            else
738
            {
739
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
740
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
741
                    points[points.Count - 1][0],
742
                    points[points.Count - 1][1],
743
                    points[points.Count - 2][0],
744
                    points[points.Count - 2][1]);
745
            }
746

    
747
            for (int i = 0; i < points.Count; i++)
748
            {
749
                double[] point = points[i];
750
                if (i == 0)
751
                {
752
                    if (IsStart)
753
                    {
754
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
755
                    }
756
                    else
757
                    {
758
                        if (_SameRunTargetConnector != null)
759
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
760
                        else if (_SameRunTargetSymbol != null)
761
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
762
                        else
763
                            placeRunInputs.AddPoint(point[0], point[1]);
764
                    }
765
                }
766
                else if (i == points.Count - 1)
767
                {
768
                    if (IsStart)
769
                    {
770
                        if (_SameRunTargetConnector != null)
771
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
772
                        else if (_SameRunTargetSymbol != null)
773
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
774
                        else
775
                            placeRunInputs.AddPoint(point[0], point[1]);
776
                    }
777
                    else
778
                    {
779
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
780
                    }
781
                }
782
                else
783
                    placeRunInputs.AddPoint(point[0], point[1]);
784
            }
785
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
786
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
787

    
788
            if (_LMConnector != null)
789
            {
790
                if (_SameRunTargetConnector != null)
791
                {
792
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
793
                }
794
                else
795
                {
796
                    foreach (var item in lines)
797
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
798
                }
799

    
800
                _LMConnector.Commit();
801
                ReleaseCOMObjects(_LMConnector);
802
            }
803

    
804
            ReleaseCOMObjects(placeRunInputs);
805
            ReleaseCOMObjects(_LMAItem);
806
            if (_BranchTargetConnector != null)
807
                ReleaseCOMObjects(_BranchTargetConnector);
808
            if (_SameRunTargetConnector != null)
809
                ReleaseCOMObjects(_SameRunTargetConnector);
810
            if (_SameRunTargetSymbol != null)
811
                ReleaseCOMObjects(_SameRunTargetSymbol);
812
            foreach (var item in connectorVertices)
813
                ReleaseCOMObjects(item.Key);
814
            foreach (var item in branchConnectorVertices)
815
                ReleaseCOMObjects(item.Key);
816
        }
817

    
818
        private void EndBreakModeling(EndBreak endBreak)
819
        {
820
            Line ownerLine = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER) as Line;
821
            
822
            if (ownerLine != null)
823
            {
824
                LMLabelPersist _LmLabelPersist = null;
825
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
826

    
827
                LMConnector connectedLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
828
                if (connectedLMConnector != null)
829
                {
830
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
831
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
832
                    ReleaseCOMObjects(connectedLMConnector);
833
                }
834

    
835
                if (_LmLabelPersist != null)
836
                {
837
                    _LmLabelPersist.Commit();
838
                    ReleaseCOMObjects(_LmLabelPersist);
839
                }
840
                foreach (var item in connectorVertices)
841
                    ReleaseCOMObjects(item.Key);
842
            }
843
        }
844

    
845
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
846
        {
847
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
848
            _LMAItem item1 = modelItem1.AsLMAItem();
849
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
850
            _LMAItem item2 = modelItem2.AsLMAItem();
851
            
852
            // item2가 item1으로 조인
853
            try
854
            {
855
                _placement.PIDJoinRuns(ref item1, ref item2);
856
                item1.Commit();
857
                item2.Commit();
858
            }
859
            catch (Exception ex)
860
            {
861
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
862
            }
863
            finally
864
            {
865
                ReleaseCOMObjects(modelItem1);
866
                ReleaseCOMObjects(item1);
867
                ReleaseCOMObjects(modelItem2);
868
                ReleaseCOMObjects(item2);
869
            }
870
        }
871

    
872
        private void AutoJoinPipeRun(string modelItemId)
873
        {
874
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
875
            _LMAItem item = modelItem.AsLMAItem();
876
            try
877
            {
878
                string modelitemID = item.Id;
879
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
880
                string afterModelItemID = item.Id;
881
                if (modelitemID != afterModelItemID)
882
                {
883
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
884
                    foreach (var line in lines)
885
                        line.SPPID.ModelItemId = afterModelItemID;
886
                }
887
                item.Commit();
888
            }
889
            catch (Exception ex)
890
            {
891
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
892
            }
893
            finally
894
            {
895
                ReleaseCOMObjects(modelItem);
896
                ReleaseCOMObjects(item);
897
            }
898
        }
899

    
900
        private void JoinRunLine(LineRun run)
901
        {
902
            string modelItemId = string.Empty;
903
            foreach (var item in run.RUNITEMS)
904
            {
905
                if (item.GetType() == typeof(Line))
906
                {
907
                    Line line = item as Line;
908
                    if (modelItemId != line.SPPID.ModelItemId)
909
                    {
910
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
911
                        modelItemId = line.SPPID.ModelItemId;
912
                    }
913
                }
914
            }
915
        }
916

    
917
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
918
        {
919
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
920
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
921

    
922
            if (modelItem != null)
923
            {
924
                foreach (LMRepresentation rep in modelItem.Representations)
925
                {
926
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
927
                    {
928
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
929
                        connectorVertices.Add(_LMConnector, new List<double[]>());
930
                        dynamic OID = rep.get_GraphicOID();
931
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
932
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
933
                        int verticesCount = lineStringGeometry.VertexCount;
934
                        double[] vertices = null;
935
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
936
                        for (int i = 0; i < verticesCount; i++)
937
                        {
938
                            double x = 0;
939
                            double y = 0;
940
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
941
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
942
                        }
943
                    }
944
                }
945

    
946
                ReleaseCOMObjects(modelItem);
947
            }
948

    
949
            return connectorVertices;
950
        }
951

    
952
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
953
        {
954
            double length = double.MaxValue;
955
            LMConnector targetConnector = null;
956
            foreach (var item in connectorVertices)
957
            {
958
                List<double[]> points = item.Value;
959
                for (int i = 0; i < points.Count - 1; i++)
960
                {
961
                    double[] point1 = points[i];
962
                    double[] point2 = points[i + 1];
963

    
964
                    double maxLineX = Math.Max(point1[0], point2[0]);
965
                    double minLineX = Math.Min(point1[0], point2[0]);
966
                    double maxLineY = Math.Max(point1[1], point2[1]);
967
                    double minLineY = Math.Min(point1[1], point2[1]);
968

    
969
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
970

    
971
                    // 두직선의 교차점
972
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
973
                    if (crossingPoint != null)
974
                    {
975
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
976
                        if (length >= distance)
977
                        {
978
                            if (slope == SlopeType.Slope &&
979
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
980
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
981
                            {
982
                                targetConnector = item.Key;
983
                                length = distance;
984
                            }
985
                            else if (slope == SlopeType.HORIZONTAL &&
986
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
987
                            {
988
                                targetConnector = item.Key;
989
                                length = distance;
990
                            }
991
                            else if (slope == SlopeType.VERTICAL &&
992
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
993
                            {
994
                                targetConnector = item.Key;
995
                                length = distance;
996
                            }
997
                        }
998
                    }
999
                }
1000
            }
1001

    
1002
            return targetConnector;
1003
        }
1004

    
1005
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1006
        {
1007
            double length = double.MaxValue;
1008
            LMConnector targetConnector = null;
1009
            foreach (var item in connectorVertices)
1010
            {
1011
                List<double[]> points = item.Value;
1012

    
1013
                foreach (double[] point in points)
1014
                {
1015
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1016
                    if (length >= distance)
1017
                    {
1018
                        targetConnector = item.Key;
1019
                        length = distance;
1020
                    }
1021
                }
1022
            }
1023

    
1024
            return targetConnector;
1025
        }
1026

    
1027
        private void LineNumberModeling(LineNumber lineNumber)
1028
        {
1029
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1030
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
1031
            LMConnector connectedLMConnector = FindTargetLMConnectorByPoint(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
1032
            if (connectedLMConnector != null)
1033
            {
1034
                Array points = new double[] { 0, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y };
1035
                LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
1036
                _LmLabelPresist.Commit();
1037

    
1038
                foreach (var item in connectorVertices)
1039
                    ReleaseCOMObjects(item.Key);
1040
                if (_LmLabelPresist != null)
1041
                {
1042
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1043
                    ReleaseCOMObjects(_LmLabelPresist);
1044
                }
1045
            }
1046
        }
1047

    
1048
        private void InputLineNumberAttribute(LineNumber lineNumber)
1049
        {
1050
            foreach (var run in lineNumber.RUNS)
1051
            {
1052
                foreach (var item in run.RUNITEMS)
1053
                {
1054
                    if (item.GetType() == typeof(Line))
1055
                    {
1056
                        Line line = item as Line;
1057
                        LMPipeRun _LMPipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId);
1058
                        foreach (var attribute in lineNumber.ATTRIBUTES)
1059
                        {
1060
                            LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1061
                            if (mapping != null)
1062
                            {
1063
                                LMAAttribute _LMAAttribute = _LMPipeRun.Attributes[mapping.SPPIDATTRIBUTENAME];
1064
                                if (_LMAAttribute != null)
1065
                                {
1066
                                    if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1067
                                        _LMAAttribute.set_Value(attribute.VALUE);
1068
                                    else if (_LMAAttribute.get_Value() != attribute.VALUE)
1069
                                        _LMAAttribute.set_Value(attribute.VALUE);
1070
                                }
1071
                            }
1072
                        }
1073

    
1074
                        _LMPipeRun.Commit();
1075
                        ReleaseCOMObjects(_LMPipeRun);
1076
                        break;
1077
                    }
1078
                }
1079
            }
1080
        }
1081

    
1082
        private void InputSymbolAttribute(Symbol symbol)
1083
        {
1084
            try
1085
            {
1086
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1087
                {
1088
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1089
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1090
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
1091

    
1092
                    foreach (var item in symbol.PROPERTIES)
1093
                    {
1094

    
1095

    
1096
                    }
1097

    
1098
                    foreach (var item in symbol.ATTRIBUTES)
1099
                    {
1100
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1101
                        if (mapping != null)
1102
                        {
1103
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1104
                            if (_Attribute != null)
1105
                                _Attribute.set_Value(item.VALUE.Replace(" ", ""));
1106
                        }
1107
                    }
1108

    
1109
                    foreach (var item in symbol.ASSOCIATIONS)
1110
                    {
1111

    
1112
                    }
1113

    
1114
                    ReleaseCOMObjects(_LMSymbol);
1115
                    ReleaseCOMObjects(_Attributes);
1116
                    ReleaseCOMObjects(_LMModelItem);
1117
                }
1118
            }
1119
            catch (Exception ex)
1120
            {
1121
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1122
            }
1123
        }
1124

    
1125
        private void TextModeling(Text text)
1126
        {
1127
            LMSymbol _LMSymbol = null;
1128
            try
1129
            {
1130
                if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
1131
                {
1132
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
1133
                    if (owner.GetType() == typeof(Symbol))
1134
                    {
1135
                        Symbol symbol = owner as Symbol;
1136
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1137
                        if (_LMSymbol != null)
1138
                        {
1139
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
1140
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
1141
                            AttributeMapping mapping = null;
1142
                            foreach (var attribute in attributes)
1143
                            {
1144
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
1145
                                if (mapping != null)
1146
                                    break;  
1147
                            }
1148

    
1149
                            if (mapping != null)
1150
                            {
1151
                                Array array = new double[] { 0, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y };
1152
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: true);
1153
                                if (_LMLabelPersist!=null)
1154
                                {
1155
                                    _LMLabelPersist.Commit();
1156
                                    ReleaseCOMObjects(_LMLabelPersist);
1157
                                }
1158
                            }
1159
                        }
1160
                    }
1161
                    else if (owner.GetType() == typeof(Line))
1162
                    {
1163

    
1164
                    }
1165
                }
1166
                else
1167
                {
1168
                    LMItemNote _LMItemNote = null;
1169
                    LMAAttribute _LMAAttribute = null;
1170

    
1171
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
1172
                    _LMSymbol.Commit();
1173
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1174
                    _LMItemNote.Commit();
1175
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1176
                    _LMAAttribute.set_Value(text.VALUE);
1177
                    _LMItemNote.Commit();
1178

    
1179
                    if (_LMAAttribute != null)
1180
                        ReleaseCOMObjects(_LMAAttribute);
1181
                    if (_LMItemNote != null)
1182
                        ReleaseCOMObjects(_LMItemNote);
1183
                }
1184
            }
1185
            catch (Exception ex)
1186
            {
1187

    
1188
            }
1189
            finally
1190
            {
1191
                if (_LMSymbol != null)
1192
                    ReleaseCOMObjects(_LMSymbol);
1193
            }
1194
        }
1195

    
1196
        private void NoteModeling(Note note)
1197
        {
1198
            LMSymbol _LMSymbol = null;
1199
            LMItemNote _LMItemNote = null;
1200
            LMAAttribute _LMAAttribute = null;
1201

    
1202
            try
1203
            {
1204
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y);
1205
                _LMSymbol.Commit();
1206
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1207
                _LMItemNote.Commit();
1208
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1209
                _LMAAttribute.set_Value(note.VALUE);
1210
                _LMItemNote.Commit();
1211
            }
1212
            catch (Exception ex)
1213
            {
1214

    
1215
            }
1216
            finally
1217
            {
1218
                if (_LMAAttribute != null)
1219
                    ReleaseCOMObjects(_LMAAttribute);
1220
                if (_LMItemNote != null)
1221
                    ReleaseCOMObjects(_LMItemNote);
1222
                if (_LMSymbol != null)
1223
                    ReleaseCOMObjects(_LMSymbol);
1224
            }
1225
            
1226
        }
1227

    
1228
        public void ReleaseCOMObjects(params object[] objVars)
1229
        {
1230
            int intNewRefCount = 0;
1231
            foreach (object obj in objVars)
1232
            {
1233
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1234
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1235
            }
1236
        }
1237
    }
1238
}
클립보드 이미지 추가 (최대 크기: 500 MB)