프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 4b4dbca9

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

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

    
24
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
            catch (Exception ex)
117
            {
118
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
119
            }
120
            finally
121
            {
122
                ReleaseCOMObjects(dataSource);
123
                ReleaseCOMObjects(_placement);
124
            }
125

    
126
            //System.Windows.Forms.MessageBox.Show("end");
127
        }
128

    
129
        public void Test()
130
        {
131
            _placement = new Placement();
132
            dataSource = _placement.PIDDataSource;
133

    
134
            DependencyObject drawingObject = radApp.ActiveDocument.SelectSet[0] as DependencyObject;
135
            if (drawingObject != null)
136
            {
137
                string modelitemID = drawingObject.AttributeSets[0][5].GetValue().ToString();
138
                radApp.ActiveDocument.SelectSet.RemoveAll();
139
                LMPipeRun run = dataSource.GetPipeRun(modelitemID);
140
                _LMAItem item = run.AsLMAItem();
141
                string modelitemID2 = item.Id;
142
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
143
                string afterModelItemID = item.Id;
144
                if (modelitemID2 != afterModelItemID)
145
                {
146

    
147
                }
148
            }
149
        }
150

    
151
        private void LineModelingByRun(LineRun run)
152
        {
153
            Line prevLine = null;
154
            List<Line> lines = new List<Line>();
155
            foreach (var item in run.RUNITEMS)
156
            {
157
                // Line일 경우
158
                if (item.GetType() == typeof(Line))
159
                {
160
                    Line line = item as Line;
161
                    if (prevLine == null)
162
                        lines.Add(line);
163
                    else if (prevLine != null)
164
                    {
165
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
166
                            lines.Add(line);
167
                        else
168
                        {
169
                            LineModeling(lines);
170
                            lines.Clear();
171
                            lines.Add(line);
172
                        }
173
                    }
174

    
175
                    prevLine = line;
176
                }
177
                // Symbol 일 경우
178
                else if (item.GetType() == typeof(Symbol))
179
                {
180
                    if (lines.Count > 0)
181
                    {
182
                        LineModeling(lines);
183
                        lines.Clear();
184
                    }
185
                }
186
            }
187

    
188
            if (lines.Count > 0)
189
                LineModeling(lines);
190
        }
191

    
192
        private void SymbolModelingByRun(LineRun run)
193
        {
194
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
195
            if (run.RUNITEMS.Count > 0)
196
            {
197
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
198
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
199

    
200
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
201
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
202
            }
203

    
204
            Symbol prevSymbol = null;
205
            Symbol targetSymbol = null;
206
            foreach (var item in run.RUNITEMS)
207
            {
208
                if (item.GetType() == typeof(Symbol))
209
                {
210
                    Symbol symbol = item as Symbol;
211
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
212
                    prevSymbol = symbol;
213
                    targetSymbol = symbol;
214
                }
215
                else
216
                {
217
                    targetSymbol = null;
218
                }
219
            }
220
        }
221

    
222
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
223
        {
224
            foreach (var connector in symbol.CONNECTORS)
225
            {
226
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
227
                if (targetItem != null &&
228
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
229
                    !IsSameLineNumber(symbol, targetItem))
230
                {
231
                    SymbolModeling(symbol, targetItem as Symbol, null);
232
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
233
                    {
234
                        object item = run.RUNITEMS[i];
235
                        if (item.GetType() == typeof(Symbol))
236
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
237
                        else
238
                            break;
239
                    }
240
                    break;
241
                }
242
            }
243

    
244

    
245
        }
246

    
247
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
248
        {
249
            foreach (var connector in symbol.CONNECTORS)
250
            {
251
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
252
                if (targetItem != null &&
253
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
254
                    !IsSameLineNumber(symbol, targetItem))
255
                {
256
                    SymbolModeling(symbol, targetItem as Symbol, null);
257
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
258
                    {
259
                        object item = run.RUNITEMS[i];
260
                        if (item.GetType() == typeof(Symbol))
261
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
262
                        else
263
                            break;
264
                    }
265
                    break;
266
                }
267
            }
268
        }
269

    
270
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
271
        {
272
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
273
                return;
274

    
275
            LMSymbol _LMSymbol = null;
276

    
277
            string mappingPath = symbol.SPPID.MAPPINGNAME;
278
            double x = symbol.SPPID.ORIGINAL_X;
279
            double y = symbol.SPPID.ORIGINAL_Y;
280
            int mirror = 0;
281
            double angle = symbol.ANGLE;
282

    
283
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
284
            {
285
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
286
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
287
                ReleaseCOMObjects(_TargetItem);
288
            }
289
            else if (prevSymbol != null)
290
            {
291
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
292
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
293
                double prevX = _PrevSymbol.get_XCoordinate();
294
                double prevY = _PrevSymbol.get_YCoordinate();
295
                if (slopeType == SlopeType.HORIZONTAL)
296
                    y = prevY;
297
                else if (slopeType == SlopeType.VERTICAL)
298
                    x = prevX;
299
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
300
            }
301
            else
302
            {
303
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
304
            }
305

    
306

    
307
            if (_LMSymbol != null)
308
            {
309
                _LMSymbol.Commit();
310
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
311

    
312
                foreach (var item in symbol.ChildSymbols)
313
                    CreateChildSymbol(item, _LMSymbol);
314
            }
315

    
316
            ReleaseCOMObjects(_LMSymbol);
317
        }
318

    
319
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
320
        {
321
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
322
            double x1 = 0;
323
            double x2 = 0;
324
            double y1 = 0;
325
            double y2 = 0;
326
            symbol2d.Range(out x1, out y1, out x2, out y2);
327

    
328
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
329
            if (_LMSymbol != null)
330
            {
331
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
332
                foreach (var item in childSymbol.ChildSymbols)
333
                    CreateChildSymbol(item, _LMSymbol);
334
            }
335
            
336

    
337
            ReleaseCOMObjects(_LMSymbol);
338
        }
339

    
340
        private bool IsSameLineNumber(object item, object targetItem)
341
        {
342
            foreach (var lineNumber in document.LINENUMBERS)
343
            {
344
                foreach (var run in lineNumber.RUNS)
345
                {
346
                    foreach (var runItem in run.RUNITEMS)
347
                    {
348
                        if (runItem == item)
349
                        {
350
                            foreach (var findItem in run.RUNITEMS)
351
                            {
352
                                if (findItem == targetItem)
353
                                {
354
                                    return true;
355
                                }
356
                            }
357

    
358
                            return false;
359

    
360
                        }
361
                    }
362
                }
363
            }
364

    
365
            return false;
366
        }
367

    
368
        private void LineModeling(List<Line> lines)
369
        {
370
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
371
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
372
            LMSymbol _LMSymbol1 = null;
373
            LMSymbol _LMSymbol2 = null;
374
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
375
            LMConnector targetConnector1 = null;
376
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
377
            LMConnector targetConnector2 = null;
378

    
379
            Line startBranchLine = null;
380
            Line endBranchLine = null;
381

    
382
            for (int i = 0; i < lines.Count; i++)
383
            {
384
                Line line = lines[i];
385
                if (i == 0 || i + 1 != lines.Count)
386
                {
387
                    // 시작점에 연결된 Symbol 찾기
388
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
389
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
390
                    {
391
                        _LMSymbol1 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId);
392
                        if (_LMSymbol1 != null)
393
                            placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y);
394
                        else
395
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
396
                    }
397
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
398
                    {
399
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
400
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
401

    
402
                        if (targetConnector1 != null)
403
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
404
                        else
405
                        {
406
                            startBranchLine = connItem as Line;
407
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
408
                        }
409
                    }
410
                    else
411
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
412
                }
413

    
414
                if (i + 1 == lines.Count)
415
                {
416
                    // 끝점에 연결된 Symbol 찾기
417
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
418

    
419
                    if (i != 0)
420
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
421

    
422
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
423
                    {
424
                        _LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId);
425
                        if (_LMSymbol2 != null)
426
                            placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y);
427
                        else
428
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
429
                            
430
                    }
431
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
432
                    {
433
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
434
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
435

    
436
                        if (targetConnector2 != null)
437
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
438
                        else
439
                        {
440
                            endBranchLine = connItem as Line;
441
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
442
                        }
443
                    }
444
                    else
445
                    {
446
                        placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
447
                    }
448
                }
449
            }
450

    
451
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
452

    
453
            if (_lMConnector != null)
454
            {
455
                foreach (var line in lines)
456
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
457
                _lMConnector.Commit();
458
                if (startBranchLine != null || endBranchLine != null)
459
                {
460
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
461
                }
462
            }
463

    
464

    
465
            if (_LMSymbol1 != null)
466
                ReleaseCOMObjects(_LMSymbol1);
467
            if (_LMSymbol2 != null)
468
                ReleaseCOMObjects(_LMSymbol2);
469
            if (targetConnector1 != null)
470
                ReleaseCOMObjects(targetConnector1);
471
            if (targetConnector2 != null)
472
                ReleaseCOMObjects(targetConnector2);
473
            foreach (var item in connectorVertices1)
474
                ReleaseCOMObjects(item.Key);
475
            foreach (var item in connectorVertices2)
476
                ReleaseCOMObjects(item.Key);
477

    
478
            ReleaseCOMObjects(_lMConnector);
479
            ReleaseCOMObjects(placeRunInputs);
480
            ReleaseCOMObjects(_LMAItem);
481
        }
482

    
483
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
484
        {
485
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
486
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
487

    
488
            LMConnector _StartConnector = null;
489
            LMConnector _EndConnector = null;
490
            double lengthStart = double.MaxValue;
491
            double lengthEnd = double.MaxValue;
492
            List<double[]> startPoints = new List<double[]>();
493
            List<double[]> endPoints = new List<double[]>();
494

    
495
            foreach (var item in connectorVertices)
496
            {
497
                foreach (var point in item.Value)
498
                {
499
                    // Start Point가 Branch
500
                    if (branch.Item2 != null)
501
                    {
502
                        Line targetLine = branch.Item2;
503
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
504
                        if (lengthStart > distance)
505
                        {
506
                            _StartConnector = item.Key;
507
                            lengthStart = distance;
508
                            startPoints = item.Value;
509
                        }
510
                    }
511
                    // End Point가 Branch
512
                    if (branch.Item3 != null)
513
                    {
514
                        Line targetLine = branch.Item3;
515
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
516
                        if (lengthEnd > distance)
517
                        {
518
                            _EndConnector = item.Key;
519
                            lengthEnd = distance;
520
                            endPoints = item.Value;
521
                        }
522
                    }
523
                }
524
            }
525
            #region Branch가 양쪽 전부일 때
526
            if (_StartConnector != null && _StartConnector == _EndConnector)
527
            {
528
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
529

    
530
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
531
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
532

    
533
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
534
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
535
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
536
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
537
                   startPoints[startPoints.Count - 1][0],
538
                   startPoints[startPoints.Count - 1][1],
539
                   startPoints[startPoints.Count - 2][0],
540
                   startPoints[startPoints.Count - 2][1]);
541

    
542
                for (int i = 0; i < startPoints.Count; i++)
543
                {
544
                    double[] point = startPoints[i];
545
                    if (i == 0)
546
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
547
                    else if (i == startPoints.Count - 1)
548
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
549
                    else
550
                        placeRunInputs.AddPoint(point[0], point[1]);
551
                }
552

    
553
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
554
                if (_LMConnector != null)
555
                {
556
                    _LMConnector.Commit();
557
                    foreach (var item in lines)
558
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
559
                }
560

    
561
                foreach (var item in startConnectorVertices)
562
                    ReleaseCOMObjects(item.Key);
563
                foreach (var item in endConnectorVertices)
564
                    ReleaseCOMObjects(item.Key);
565
                ReleaseCOMObjects(placeRunInputs);
566
                ReleaseCOMObjects(_LMAItem);
567
                ReleaseCOMObjects(_LMConnector);
568
            }
569
            #endregion
570
            #region 양쪽이 다른 Branch 
571
            else
572
            {
573
                // Branch 시작 Connector
574
                if (_StartConnector != null)
575
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
576

    
577
                // Branch 끝 Connector
578
                if (_EndConnector != null)
579
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
580
            }
581
            #endregion
582

    
583
            if (_StartConnector != null)
584
                ReleaseCOMObjects(_StartConnector);
585
            if (_EndConnector != null)
586
                ReleaseCOMObjects(_EndConnector);
587
            foreach (var item in connectorVertices)
588
                ReleaseCOMObjects(item.Key);
589
        }
590

    
591
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
592
        {
593
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
594
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
595
            LMConnector _SameRunTargetConnector = null;
596
            LMSymbol _SameRunTargetSymbol = null;
597
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
598
            LMConnector _BranchTargetConnector = null;
599
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
600

    
601
            // 같은 Line Run의 Connector 찾기
602
            foreach (var item in connectorVertices)
603
            {
604
                if (item.Key == _Connector)
605
                    continue;
606

    
607
                if (IsStart &&
608
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
609
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
610
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
611
                {
612
                    _SameRunTargetConnector = item.Key;
613
                    break;
614
                }
615
                else if (!IsStart &&
616
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
617
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
618
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
619
                {
620
                    _SameRunTargetConnector = item.Key;
621
                    break;
622
                }
623
            }
624

    
625
            // Branch 반대편이 Symbol
626
            if (_SameRunTargetConnector == null)
627
            {
628
                foreach (var line in lines)
629
                {
630
                    foreach (var connector in line.CONNECTORS)
631
                    {
632
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
633
                        if (symbol != null)
634
                        {
635
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
636
                            break;
637
                        }
638
                    }
639
                }
640
            }
641

    
642
            // 기존 Connector 제거
643
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
644
            
645
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
646
            if (IsStart)
647
            {
648
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
649
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
650
            }
651
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
652
            else
653
            {
654
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
655
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
656
                    points[points.Count - 1][0],
657
                    points[points.Count - 1][1],
658
                    points[points.Count - 2][0],
659
                    points[points.Count - 2][1]);
660
            }
661

    
662
            for (int i = 0; i < points.Count; i++)
663
            {
664
                double[] point = points[i];
665
                if (i == 0)
666
                {
667
                    if (IsStart)
668
                    {
669
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
670
                    }
671
                    else
672
                    {
673
                        if (_SameRunTargetConnector != null)
674
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
675
                        else if (_SameRunTargetSymbol != null)
676
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
677
                        else
678
                            placeRunInputs.AddPoint(point[0], point[1]);
679
                    }
680
                }
681
                else if (i == points.Count - 1)
682
                {
683
                    if (IsStart)
684
                    {
685
                        if (_SameRunTargetConnector != null)
686
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
687
                        else if (_SameRunTargetSymbol != null)
688
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
689
                        else
690
                            placeRunInputs.AddPoint(point[0], point[1]);
691
                    }
692
                    else
693
                    {
694
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
695
                    }
696
                }
697
                else
698
                    placeRunInputs.AddPoint(point[0], point[1]);
699
            }
700
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
701
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
702

    
703
            if (_LMConnector != null)
704
            {
705
                if (_SameRunTargetConnector != null)
706
                {
707
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
708
                }
709
                else
710
                {
711
                    foreach (var item in lines)
712
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
713
                }
714

    
715
                _LMConnector.Commit();
716
                ReleaseCOMObjects(_LMConnector);
717
            }
718

    
719
            ReleaseCOMObjects(placeRunInputs);
720
            ReleaseCOMObjects(_LMAItem);
721
            if (_BranchTargetConnector != null)
722
                ReleaseCOMObjects(_BranchTargetConnector);
723
            if (_SameRunTargetConnector != null)
724
                ReleaseCOMObjects(_SameRunTargetConnector);
725
            if (_SameRunTargetSymbol != null)
726
                ReleaseCOMObjects(_SameRunTargetSymbol);
727
            foreach (var item in connectorVertices)
728
                ReleaseCOMObjects(item.Key);
729
            foreach (var item in branchConnectorVertices)
730
                ReleaseCOMObjects(item.Key);
731
        }
732

    
733
        private void EndBreakModeling(EndBreak endBreak)
734
        {
735
            Line ownerLine = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER) as Line;
736
            
737
            if (ownerLine != null)
738
            {
739
                LMLabelPersist _LmLabelPersist = null;
740
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
741

    
742
                LMConnector connectedLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
743
                if (connectedLMConnector != null)
744
                {
745
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
746
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
747
                    ReleaseCOMObjects(connectedLMConnector);
748
                }
749

    
750
                if (_LmLabelPersist != null)
751
                {
752
                    _LmLabelPersist.Commit();
753
                    ReleaseCOMObjects(_LmLabelPersist);
754
                }
755
                foreach (var item in connectorVertices)
756
                    ReleaseCOMObjects(item.Key);
757
            }
758
        }
759

    
760
        private bool ExistConnItem(LMPipeRun _LMPipeRun, string ConnItem)
761
        {
762
            foreach (LMRepresentation rep in _LMPipeRun.Representations)
763
            {
764
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
765
                {
766
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
767
                    if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && _LMConnector.ConnectItem1SymbolID == ConnItem)
768
                    {
769
                        ReleaseCOMObjects(_LMConnector);
770
                        return true;
771
                    }
772
                    else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && _LMConnector.ConnectItem2SymbolID == ConnItem)
773
                    {
774
                        ReleaseCOMObjects(_LMConnector);
775
                        return true;
776
                    }
777
                    else
778
                    {
779
                        ReleaseCOMObjects(_LMConnector);
780
                    }
781
                }
782
            }
783

    
784
            return false;
785
        }
786

    
787
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
788
        {
789
            LMPipeRun run1 = dataSource.GetPipeRun(toModelItemId);
790
            LMPipeRun run2 = dataSource.GetPipeRun(fromModelItemId);
791
            // item2가 item1으로 조인
792
            try
793
            {
794
                _LMAItem item1 = run1.AsLMAItem();
795
                _LMAItem item2 = run2.AsLMAItem();
796

    
797
                _placement.PIDJoinRuns(ref item1, ref item2);
798
                item1.Commit();
799
                item2.Commit();
800
            }
801
            catch (Exception ex)
802
            {
803
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
804
            }
805
            finally
806
            {
807
                ReleaseCOMObjects(run1);
808
                ReleaseCOMObjects(run2);
809
            }
810
        }
811

    
812
        private void AutoJoinPipeRun(string modelItemId)
813
        {
814
            LMPipeRun run = dataSource.GetPipeRun(modelItemId);
815
            try
816
            {
817
                _LMAItem item = run.AsLMAItem();
818
                string modelitemID = item.Id;
819
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
820
                string afterModelItemID = item.Id;
821
                if (modelitemID != afterModelItemID)
822
                {
823
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
824
                    foreach (var line in lines)
825
                        line.SPPID.ModelItemId = afterModelItemID;
826
                }
827
                item.Commit();
828
            }
829
            catch (Exception ex)
830
            {
831
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
832
            }
833
            finally
834
            {
835
                ReleaseCOMObjects(run);
836
            }
837
        }
838

    
839
        private void JoinRunLine(LineRun run)
840
        {
841
            string modelItemId = string.Empty;
842
            foreach (var item in run.RUNITEMS)
843
            {
844
                if (item.GetType() == typeof(Line))
845
                {
846
                    Line line = item as Line;
847
                    if (modelItemId != line.SPPID.ModelItemId)
848
                    {
849
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
850
                        modelItemId = line.SPPID.ModelItemId;
851
                    }
852
                }
853
            }
854
        }
855

    
856
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
857
        {
858
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
859
            LMPipeRun _LMPipeRun = dataSource.GetPipeRun(modelId);
860
            if (_LMPipeRun != null)
861
            {
862
                foreach (LMRepresentation rep in _LMPipeRun.Representations)
863
                {
864
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
865
                    {
866
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
867
                        connectorVertices.Add(_LMConnector, new List<double[]>());
868
                        dynamic OID = rep.get_GraphicOID();
869
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
870
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
871
                        int verticesCount = lineStringGeometry.VertexCount;
872
                        double[] vertices = null;
873
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
874
                        for (int i = 0; i < verticesCount; i++)
875
                        {
876
                            double x = 0;
877
                            double y = 0;
878
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
879
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
880
                        }
881
                    }
882
                }
883

    
884
                ReleaseCOMObjects(_LMPipeRun);
885
            }
886

    
887
            return connectorVertices;
888
        }
889

    
890
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
891
        {
892
            double length = double.MaxValue;
893
            LMConnector targetConnector = null;
894
            foreach (var item in connectorVertices)
895
            {
896
                List<double[]> points = item.Value;
897
                for (int i = 0; i < points.Count - 1; i++)
898
                {
899
                    double[] point1 = points[i];
900
                    double[] point2 = points[i + 1];
901

    
902
                    double maxLineX = Math.Max(point1[0], point2[0]);
903
                    double minLineX = Math.Min(point1[0], point2[0]);
904
                    double maxLineY = Math.Max(point1[1], point2[1]);
905
                    double minLineY = Math.Min(point1[1], point2[1]);
906

    
907
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
908

    
909
                    // 두직선의 교차점
910
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
911
                    if (crossingPoint != null)
912
                    {
913
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
914
                        if (length >= distance)
915
                        {
916
                            if (slope == SlopeType.Slope &&
917
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
918
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
919
                            {
920
                                targetConnector = item.Key;
921
                                length = distance;
922
                            }
923
                            else if (slope == SlopeType.HORIZONTAL &&
924
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
925
                            {
926
                                targetConnector = item.Key;
927
                                length = distance;
928
                            }
929
                            else if (slope == SlopeType.VERTICAL &&
930
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
931
                            {
932
                                targetConnector = item.Key;
933
                                length = distance;
934
                            }
935
                        }
936
                    }
937
                }
938
            }
939

    
940
            return targetConnector;
941
        }
942

    
943
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
944
        {
945
            double length = double.MaxValue;
946
            LMConnector targetConnector = null;
947
            foreach (var item in connectorVertices)
948
            {
949
                List<double[]> points = item.Value;
950

    
951
                foreach (double[] point in points)
952
                {
953
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
954
                    if (length >= distance)
955
                    {
956
                        targetConnector = item.Key;
957
                        length = distance;
958
                    }
959
                }
960
            }
961

    
962
            return targetConnector;
963
        }
964

    
965
        private void LineNumberModeling(LineNumber lineNumber)
966
        {
967
            Line line = null;
968
            foreach (var lineRun in lineNumber.RUNS)
969
            {
970
                foreach (var item in lineRun.RUNITEMS)
971
                {
972
                    line = item as Line;
973
                    if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId))
974
                        break;
975
                    else
976
                        line = null;
977
                }
978
                if (line != null)
979
                    break;
980
            }
981

    
982
            if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId))
983
            {
984
                Array points = new double[] { 0, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y };
985
                LMPipeRun _pipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId);
986
                if (_pipeRun != null)
987
                {
988
                    foreach (LMRepresentation rep in _pipeRun.Representations)
989
                    {
990
                        if (rep.get_RepresentationType() == "Connector" && rep.get_ItemStatus() == "Active")
991
                        {
992
                            LMConnector _LmConnector = dataSource.GetConnector(rep.Id);
993
                            LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: _LmConnector.AsLMRepresentation(), IsLeaderVisible: false);
994
                            _LmLabelPresist.Commit();
995

    
996
                            if (_LmConnector != null)
997
                                ReleaseCOMObjects(_LmConnector);
998
                            if (_LmLabelPresist != null)
999
                            {
1000
                                lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1001
                                ReleaseCOMObjects(_LmConnector);
1002
                            }
1003

    
1004
                            break;
1005
                        }
1006
                    }
1007

    
1008
                    ReleaseCOMObjects(_pipeRun);
1009
                }
1010
            }
1011
        }
1012

    
1013
        private void InputLineNumberAttribute(LineNumber lineNumber)
1014
        {
1015
            foreach (var run in lineNumber.RUNS)
1016
            {
1017
                foreach (var item in run.RUNITEMS)
1018
                {
1019
                    if (item.GetType() == typeof(Line))
1020
                    {
1021
                        Line line = item as Line;
1022
                        LMPipeRun _LMPipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId);
1023
                        foreach (var attribute in lineNumber.ATTRIBUTES)
1024
                        {
1025
                            LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1026
                            if (mapping != null)
1027
                            {
1028
                                LMAAttribute _LMAAttribute = _LMPipeRun.Attributes[mapping.SPPIDATTRIBUTENAME];
1029
                                if (_LMAAttribute != null)
1030
                                {
1031
                                    if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1032
                                        _LMAAttribute.set_Value(attribute.VALUE);
1033
                                    else if (_LMAAttribute.get_Value() != attribute.VALUE)
1034
                                        _LMAAttribute.set_Value(attribute.VALUE);
1035
                                }
1036
                            }
1037
                        }
1038

    
1039
                        _LMPipeRun.Commit();
1040
                        ReleaseCOMObjects(_LMPipeRun);
1041
                        break;
1042
                    }
1043
                }
1044
            }
1045
        }
1046

    
1047
        private void InputSymbolAttribute(Symbol symbol)
1048
        {
1049
            try
1050
            {
1051
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1052
                {
1053
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1054
                    LMAAttributes _Attributes = null;
1055
                    LMPipingComp _LMPipingComp = null;
1056
                    LMInstrument _LMInstrument = null;
1057
                    LMOPC _LMOPC = null;
1058
                    LMNozzle _LMNozzle = null;
1059

    
1060
                    if (_LMSymbol.get_FileName().Contains("Instrumentation"))
1061
                    {
1062
                        _LMInstrument = dataSource.GetInstrument(_LMSymbol.ModelItemID);
1063
                        _Attributes = _LMInstrument.Attributes;
1064
                    }
1065
                    else if (_LMSymbol.get_FileName().Contains("OPC"))
1066
                    { 
1067
                        _LMOPC = dataSource.GetOPC(_LMSymbol.ModelItemID);
1068
                        _Attributes = _LMOPC.Attributes;
1069
                    }
1070
                    else if (_LMSymbol.get_FileName().Contains("Nozzle"))
1071
                    {
1072
                        _LMNozzle = dataSource.GetNozzle(_LMSymbol.ModelItemID);
1073
                        _Attributes = _LMNozzle.Attributes;
1074
                    }
1075
                    else
1076
                    {
1077
                        _LMPipingComp = dataSource.GetPipingComp(_LMSymbol.ModelItemID);
1078
                        _Attributes = _LMPipingComp.Attributes;
1079
                    }
1080

    
1081
                    foreach (var item in symbol.PROPERTIES)
1082
                    {
1083

    
1084

    
1085
                    }
1086

    
1087
                    foreach (var item in symbol.ATTRIBUTES)
1088
                    {
1089
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1090
                        if (mapping != null)
1091
                        {
1092
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1093
                            if (_Attribute != null)
1094
                                _Attribute.set_Value(item.VALUE.Replace(" ", ""));
1095
                        }
1096
                    }
1097

    
1098
                    foreach (var item in symbol.ASSOCIATIONS)
1099
                    {
1100

    
1101
                    }
1102

    
1103
                    ReleaseCOMObjects(_LMSymbol);
1104
                    if (_LMPipingComp != null)
1105
                    {
1106
                        _LMPipingComp.Commit();
1107
                        ReleaseCOMObjects(_LMPipingComp);
1108
                    }
1109
                    if (_LMInstrument != null)
1110
                    {
1111
                        _LMInstrument.Commit();
1112
                        ReleaseCOMObjects(_LMInstrument);
1113
                    }
1114
                    if (_LMOPC != null)
1115
                    {
1116
                        _LMOPC.Commit();
1117
                        ReleaseCOMObjects(_LMOPC);
1118
                    }
1119
                    if (_LMNozzle != null)
1120
                    {
1121
                        _LMNozzle.Commit();
1122
                        ReleaseCOMObjects(_LMNozzle);
1123
                    }
1124

    
1125

    
1126
                }
1127
            }
1128
            catch (Exception ex)
1129
            {
1130
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1131
            }
1132
        }
1133

    
1134
        private void TextModeling(Text text)
1135
        {
1136
            LMSymbol _LMSymbol = null;
1137
            LMItemNote _LMItemNote = null;
1138
            LMAAttribute _LMAAttribute = null;
1139

    
1140
            try
1141
            {
1142
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
1143
                _LMSymbol.Commit();
1144
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1145
                _LMItemNote.Commit();
1146
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1147
                _LMAAttribute.set_Value(text.VALUE);
1148
                _LMItemNote.Commit();
1149
            }
1150
            catch (Exception ex)
1151
            {
1152

    
1153
            }
1154
            finally
1155
            {
1156
                if (_LMAAttribute != null)
1157
                    ReleaseCOMObjects(_LMAAttribute);
1158
                if (_LMItemNote != null)
1159
                    ReleaseCOMObjects(_LMItemNote);
1160
                if (_LMSymbol != null)
1161
                    ReleaseCOMObjects(_LMSymbol);
1162
            }
1163
        }
1164

    
1165
        private void NoteModeling(Note note)
1166
        {
1167
            LMSymbol _LMSymbol = null;
1168
            LMItemNote _LMItemNote = null;
1169
            LMAAttribute _LMAAttribute = null;
1170

    
1171
            try
1172
            {
1173
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y);
1174
                _LMSymbol.Commit();
1175
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1176
                _LMItemNote.Commit();
1177
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1178
                _LMAAttribute.set_Value(note.VALUE);
1179
                _LMItemNote.Commit();
1180
            }
1181
            catch (Exception ex)
1182
            {
1183

    
1184
            }
1185
            finally
1186
            {
1187
                if (_LMAAttribute != null)
1188
                    ReleaseCOMObjects(_LMAAttribute);
1189
                if (_LMItemNote != null)
1190
                    ReleaseCOMObjects(_LMItemNote);
1191
                if (_LMSymbol != null)
1192
                    ReleaseCOMObjects(_LMSymbol);
1193
            }
1194
            
1195
        }
1196

    
1197
        public void ReleaseCOMObjects(params object[] objVars)
1198
        {
1199
            int intNewRefCount = 0;
1200
            foreach (object obj in objVars)
1201
            {
1202
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1203
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1204
            }
1205
        }
1206
    }
1207
}
클립보드 이미지 추가 (최대 크기: 500 MB)