프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 905f8163

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

1 cfda1fed gaqhf
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 8aa6f2db gaqhf
using Ingr.RAD2D.Interop.RAD2D;
9
using Ingr.RAD2D.Internal;
10
using Ingr.RAD2D.Helper;
11 cfda1fed gaqhf
using Converter.BaseModel;
12
using Converter.SPPID.Model;
13
using Converter.SPPID.Properties;
14
using Converter.SPPID.Util;
15
using Converter.SPPID.DB;
16 5e6ecf05 gaqhf
using Ingr.RAD2D.MacroControls.CmdCtrl;
17
using Ingr.RAD2D;
18 5dfb8a24 gaqhf
using System.Windows;
19 cfda1fed gaqhf
using System.Threading;
20 5dfb8a24 gaqhf
using System.Drawing;
21 cfda1fed gaqhf
using Microsoft.VisualBasic;
22
using Newtonsoft.Json;
23
24 ca214bc3 gaqhf
using DevExpress.XtraSplashScreen;
25 cfda1fed gaqhf
namespace Converter.SPPID
26
{
27
    public class AutoModeling
28
    {
29 809a7640 gaqhf
        Placement _placement;
30
        LMADataSource dataSource;
31 1ba9c671 gaqhf
        dynamic newDrawing;
32 d19ae675 gaqhf
        dynamic application;
33 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
34 cfda1fed gaqhf
        SPPID_Document document;
35 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
36 f1c9dbaa gaqhf
37 d5ec4d0f gaqhf
        public string DocumentLabelText { get; set; }
38
39 f31645b6 gaqhf
        int CurrentCount;
40
41
        List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42 d19ae675 gaqhf
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
43 cfda1fed gaqhf
        {
44
            this.document = document;
45 d19ae675 gaqhf
            this.application = application;
46 5e6ecf05 gaqhf
            this.radApp = radApp;
47 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
48 cfda1fed gaqhf
        }
49
50 b265df51 gaqhf
        private int ClacProgressCount()
51 f31645b6 gaqhf
        {
52 b265df51 gaqhf
            int EquipCount = 0;
53
            int SymbolCount = 0;
54
            int LineCount = 0;
55
            int NoteCount = 0;
56
            int TextCount = 0;
57
            int EndBreakCount = 0;
58
            int LineNumberCount = 0;
59
60 f31645b6 gaqhf
            EquipCount = document.Equipments.Count;
61
            SymbolCount = document.SYMBOLS.Count;
62
            SymbolCount = SymbolCount * 3;
63
            
64
            foreach (LineNumber lineNumber in document.LINENUMBERS)
65
                foreach (LineRun run in lineNumber.RUNS)
66
                    foreach (var item in run.RUNITEMS)
67
                        if (item.GetType() == typeof(Line))
68
                            LineCount++;
69
            foreach (TrimLine trimLine in document.TRIMLINES)
70
                foreach (LineRun run in trimLine.RUNS)
71
                    foreach (var item in run.RUNITEMS)
72
                        if (item.GetType() == typeof(Line))
73
                            LineCount++;
74
75
            LineCount = LineCount * 2;
76
            NoteCount = document.NOTES.Count;
77
            TextCount = document.TEXTINFOS.Count;
78
            EndBreakCount = document.EndBreaks.Count;
79
            LineNumberCount = document.LINENUMBERS.Count;
80
            LineNumberCount = LineNumberCount * 2;
81
82 b265df51 gaqhf
            return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount;
83 f31645b6 gaqhf
        }
84
85 74752074 gaqhf
        /// <summary>
86
        /// 도면 단위당 실행되는 메서드
87
        /// </summary>
88 1ba9c671 gaqhf
        public void Run()
89 c2fef4ca gaqhf
        {
90 1ba9c671 gaqhf
            try
91 c2fef4ca gaqhf
            {
92 1ba9c671 gaqhf
                _placement = new Placement();
93
                dataSource = _placement.PIDDataSource;
94
95 0e0edfad gaqhf
                CreateDocument();
96 1ba9c671 gaqhf
97 0e0edfad gaqhf
                if (DocumentCoordinateCorrection())
98 310aeb31 gaqhf
                {
99 b265df51 gaqhf
                    int AllCount = ClacProgressCount();
100 3939eebf gaqhf
101 965eb728 gaqhf
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
102 0e0edfad gaqhf
                    Thread.Sleep(1000);
103 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
104 0e0edfad gaqhf
                    Thread.Sleep(1000);
105 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount);
106 d5ec4d0f gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
107 965eb728 gaqhf
108 3939eebf gaqhf
                    // Equipment Modeling
109 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
110 3939eebf gaqhf
                    foreach (Equipment equipment in document.Equipments)
111
                        EquipmentModeling(equipment);
112
113
                    // LineRun Symbol Modeling
114 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling");
115 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
116
                        foreach (LineRun run in lineNumber.RUNS)
117
                            SymbolModelingByRun(run);
118
                    // TrimLineRun Symbol Modeling
119
                    foreach (TrimLine trimLine in document.TRIMLINES)
120
                        foreach (LineRun run in trimLine.RUNS)
121
                            SymbolModelingByRun(run);
122
123
                    // LineRun Line Modeling
124 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
125 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
126
                        foreach (LineRun run in lineNumber.RUNS)
127
                            LineModelingByRun(run);
128
                    // TrimLineRun Line Modeling
129
                    foreach (TrimLine trimLine in document.TRIMLINES)
130
                        foreach (LineRun run in trimLine.RUNS)
131
                            LineModelingByRun(run);
132
133
                    // Branch Line Modeling
134 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
135 3939eebf gaqhf
                    foreach (var item in BranchLines)
136
                        BranchLineModeling(item);
137
138
                    // EndBreak Modeling
139 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
140 3939eebf gaqhf
                    foreach (var item in document.EndBreaks)
141
                        EndBreakModeling(item);
142
143
                    // LineNumber Modeling
144 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling");
145 3939eebf gaqhf
                    foreach (var item in document.LINENUMBERS)
146
                        LineNumberModeling(item);
147
148
                    // Note Modeling
149 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
150 3939eebf gaqhf
                    foreach (var item in document.NOTES)
151
                        NoteModeling(item);
152
153
                    // Text Modeling
154 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
155 3939eebf gaqhf
                    foreach (var item in document.TEXTINFOS)
156
                        TextModeling(item);
157
158
                    // LineRun Line Join
159 73415441 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
160 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
161
                        foreach (LineRun run in lineNumber.RUNS)
162
                            JoinRunLine(run);
163
                    // TrimLineRun Line Join
164
                    foreach (TrimLine trimLine in document.TRIMLINES)
165
                        foreach (LineRun run in trimLine.RUNS)
166
                            JoinRunLine(run);
167
168
                    // Input LineNumber Attribute
169 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute");
170 3939eebf gaqhf
                    foreach (var item in document.LINENUMBERS)
171
                        InputLineNumberAttribute(item);
172
173
                    // Input Symbol Attribute
174 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
175 3939eebf gaqhf
                    foreach (var item in document.SYMBOLS)
176 73415441 gaqhf
                        InputSymbolAttribute(item, item.ATTRIBUTES);
177 3939eebf gaqhf
178 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
179 73415441 gaqhf
                    #region Label Modeling
180 3939eebf gaqhf
                    foreach (var item in document.SYMBOLS)
181 73415441 gaqhf
                        LabelSymbolModeling(item);
182 3939eebf gaqhf
                    #endregion
183 f31645b6 gaqhf
184
185
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount);
186 310aeb31 gaqhf
                }
187 809a7640 gaqhf
            }
188 5e6ecf05 gaqhf
            catch (Exception ex)
189
            {
190
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
191
            }
192
            finally
193
            {
194 1ba9c671 gaqhf
                application.ActiveWindow.Fit();
195 3939eebf gaqhf
                
196 1ba9c671 gaqhf
                if (newDrawing != null)
197 3939eebf gaqhf
                {
198
                    radApp.ActiveDocument.SaveOnClose = false;
199
                    radApp.ActiveDocument.Save();
200 1ba9c671 gaqhf
                    ReleaseCOMObjects(newDrawing);
201 3939eebf gaqhf
                }
202 1ba9c671 gaqhf
203 5e6ecf05 gaqhf
                ReleaseCOMObjects(dataSource);
204
                ReleaseCOMObjects(_placement);
205 965eb728 gaqhf
206 f31645b6 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
207 965eb728 gaqhf
                SplashScreenManager.CloseForm(false);
208 5e6ecf05 gaqhf
            }
209 65a1ed4b gaqhf
        }
210
211 74752074 gaqhf
        /// <summary>
212
        /// 도면 생성 메서드
213
        /// </summary>
214 0e0edfad gaqhf
        private void CreateDocument()
215
        {
216
            newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
217
            application.ActiveWindow.Fit();
218
            Thread.Sleep(1000);
219
            application.ActiveWindow.Zoom = 2000;
220
            Thread.Sleep(2000);
221
        }
222
223 74752074 gaqhf
        /// <summary>
224
        /// 도면 크기 구하는 메서드
225
        /// </summary>
226
        /// <returns></returns>
227 0e0edfad gaqhf
        private bool DocumentCoordinateCorrection()
228
        {
229
            double maxX = 0;
230
            double maxY = 0;
231
            foreach (object drawingObj in radApp.ActiveDocument.ActiveSheet.DrawingObjects)
232
            {
233
                Ingr.RAD2D.SmartFrame2d smartFrame2d = drawingObj as Ingr.RAD2D.SmartFrame2d;
234
                if (smartFrame2d != null)
235
                {
236
                    double x1 = 0;
237
                    double x2 = 0;
238
                    double y1 = 0;
239
                    double y2 = 0;
240
                    smartFrame2d.Range(out x1, out y1, out x2, out y2);
241
                    maxX = Math.Max(x2, maxX);
242
                    maxY = Math.Max(y2, maxY);
243
                }
244
            }
245
            if (maxX != 0 && maxY != 0)
246
            {
247
                document.SetSPPIDLocation(maxX, maxY);
248
                return true;
249
            }
250
            else
251
                return false;
252
        }
253
254 74752074 gaqhf
        /// <summary>
255
        /// 라인을 Run 단위로 모델링하는 진입 메서드
256
        /// </summary>
257
        /// <param name="run"></param>
258 8aa6f2db gaqhf
        private void LineModelingByRun(LineRun run)
259 809a7640 gaqhf
        {
260
            Line prevLine = null;
261
            List<Line> lines = new List<Line>();
262
            foreach (var item in run.RUNITEMS)
263
            {
264
                // Line일 경우
265
                if (item.GetType() == typeof(Line))
266
                {
267
                    Line line = item as Line;
268
                    if (prevLine == null)
269
                        lines.Add(line);
270
                    else if (prevLine != null)
271
                    {
272
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
273
                            lines.Add(line);
274
                        else
275 f1c9dbaa gaqhf
                        {
276 f2baa6a3 gaqhf
                            if (lines.Count > 0)
277
                            {
278
                                LineModeling(lines);
279
                                lines.Clear();
280
                            }
281 809a7640 gaqhf
                            lines.Add(line);
282 5dfb8a24 gaqhf
                        }
283
                    }
284
285 809a7640 gaqhf
                    prevLine = line;
286 f31645b6 gaqhf
287
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
288 809a7640 gaqhf
                }
289
                // Symbol 일 경우
290
                else if (item.GetType() == typeof(Symbol))
291
                {
292 f1c9dbaa gaqhf
                    if (lines.Count > 0)
293 809a7640 gaqhf
                    {
294 f1c9dbaa gaqhf
                        LineModeling(lines);
295 809a7640 gaqhf
                        lines.Clear();
296
                    }
297 5dfb8a24 gaqhf
                }
298
            }
299
300 809a7640 gaqhf
            if (lines.Count > 0)
301
                LineModeling(lines);
302
        }
303 5dfb8a24 gaqhf
304 74752074 gaqhf
        /// <summary>
305
        /// 심볼을 Run 단위로 모델링하는 진입 메서드
306
        /// </summary>
307
        /// <param name="run"></param>
308 8aa6f2db gaqhf
        private void SymbolModelingByRun(LineRun run)
309 809a7640 gaqhf
        {
310
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
311
            if (run.RUNITEMS.Count > 0)
312
            {
313
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
314
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
315
316
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
317
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
318
            }
319
320
            Symbol prevSymbol = null;
321
            Symbol targetSymbol = null;
322
            foreach (var item in run.RUNITEMS)
323
            {
324
                if (item.GetType() == typeof(Symbol))
325
                {
326
                    Symbol symbol = item as Symbol;
327
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
328
                    prevSymbol = symbol;
329
                    targetSymbol = symbol;
330
                }
331
                else
332
                {
333
                    targetSymbol = null;
334
                }
335
            }
336
        }
337
338 74752074 gaqhf
        /// <summary>
339
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점
340
        /// </summary>
341
        /// <param name="symbol"></param>
342
        /// <param name="run"></param>
343 8aa6f2db gaqhf
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
344 809a7640 gaqhf
        {
345
            foreach (var connector in symbol.CONNECTORS)
346
            {
347
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
348
                if (targetItem != null &&
349
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
350 74752074 gaqhf
                    !IsSameLineRun(symbol, targetItem))
351 809a7640 gaqhf
                {
352
                    SymbolModeling(symbol, targetItem as Symbol, null);
353
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
354
                    {
355
                        object item = run.RUNITEMS[i];
356
                        if (item.GetType() == typeof(Symbol))
357
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
358
                        else
359
                            break;
360
                    }
361
                    break;
362
                }
363
            }
364
365
366
        }
367
368 74752074 gaqhf
        /// <summary>
369
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점
370
        /// </summary>
371
        /// <param name="symbol"></param>
372
        /// <param name="run"></param>
373 8aa6f2db gaqhf
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
374 809a7640 gaqhf
        {
375
            foreach (var connector in symbol.CONNECTORS)
376
            {
377
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
378
                if (targetItem != null &&
379
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
380 74752074 gaqhf
                    !IsSameLineRun(symbol, targetItem))
381 809a7640 gaqhf
                {
382
                    SymbolModeling(symbol, targetItem as Symbol, null);
383
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
384
                    {
385
                        object item = run.RUNITEMS[i];
386
                        if (item.GetType() == typeof(Symbol))
387
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
388
                        else
389
                            break;
390
                    }
391
                    break;
392
                }
393
            }
394 5dfb8a24 gaqhf
        }
395 cfda1fed gaqhf
396 74752074 gaqhf
        /// <summary>
397
        /// 심볼을 실제로 Modeling 메서드
398
        /// </summary>
399
        /// <param name="symbol"></param>
400
        /// <param name="targetSymbol"></param>
401
        /// <param name="prevSymbol"></param>
402 809a7640 gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
403
        {
404 73415441 gaqhf
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
405
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
406
            if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None")
407 c3d2e266 gaqhf
                return;
408 73415441 gaqhf
            // 이미 모델링 됐을 경우
409
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
410 809a7640 gaqhf
                return;
411
412
            LMSymbol _LMSymbol = null;
413
414
            string mappingPath = symbol.SPPID.MAPPINGNAME;
415
            double x = symbol.SPPID.ORIGINAL_X;
416
            double y = symbol.SPPID.ORIGINAL_Y;
417
            int mirror = 0;
418
            double angle = symbol.ANGLE;
419 73415441 gaqhf
            
420
            // OPC 일경우 180도 일때 Mirror
421 c2fef4ca gaqhf
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
422
                mirror = 1;
423 809a7640 gaqhf
424
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
425
            {
426
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
427 b9e9f4c8 gaqhf
428
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
429
                double x1 = 0;
430
                double x2 = 0;
431
                double y1 = 0;
432
                double y2 = 0;
433
                symbol2d.Range(out x1, out y1, out x2, out y2);
434
435
                if (y2 < y)
436
                    y = y2;
437
                else if (y1 > y)
438
                    y = y1;
439
440
                if (x2 < x)
441
                    x = x2;
442
                else if (x1 > x)
443
                    x = x1;
444
445 809a7640 gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
446
                ReleaseCOMObjects(_TargetItem);
447
            }
448
            else if (prevSymbol != null)
449
            {
450
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
451
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
452
                double prevX = _PrevSymbol.get_XCoordinate();
453
                double prevY = _PrevSymbol.get_YCoordinate();
454
                if (slopeType == SlopeType.HORIZONTAL)
455
                    y = prevY;
456
                else if (slopeType == SlopeType.VERTICAL)
457
                    x = prevX;
458
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
459
            }
460
            else
461
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
462
463
464
            if (_LMSymbol != null)
465
            {
466
                _LMSymbol.Commit();
467
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
468 ac78b508 gaqhf
469 4b4dbca9 gaqhf
                foreach (var item in symbol.ChildSymbols)
470
                    CreateChildSymbol(item, _LMSymbol);
471 809a7640 gaqhf
            }
472
473
            ReleaseCOMObjects(_LMSymbol);
474 f31645b6 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
475 809a7640 gaqhf
        }
476
477 73415441 gaqhf
        private void LabelSymbolModeling(Symbol symbol)
478
        {
479
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
480
            if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE))
481
                return;
482
483
            Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
484
            
485
            string symbolUID = itemAttribute.VALUE;
486
            object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
487
            if (targetItem != null)
488
            {
489
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
490
                string sRep = null;
491
                if (targetItem.GetType() == typeof(Symbol))
492
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
493
                else if (targetItem.GetType() == typeof(Equipment))
494
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
495
496
                if (!string.IsNullOrEmpty(sRep))
497
                {
498
                    // LEADER Line 검사
499
                    bool leaderLine = false;
500
                    SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
501
                    if (symbolMapping != null)
502
                        leaderLine = symbolMapping.LEADERLINE;
503
504
                    // Target Symbol Item 가져오고 Label Modeling
505
                    LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
506
                    LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
507
508
                    // Target Item에 Label의 Attribute Input
509
                    InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
510
511
                    //Leader 선 센터로
512
                    string OID = _LMLabelPresist.get_GraphicOID();
513
                    DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
514
                    if (dependency != null)
515
                    {
516
                        bool result = false;
517
                        foreach (var attributes in dependency.AttributeSets)
518
                        {
519
                            foreach (var attribute in attributes)
520
                            {
521
                                string name = attribute.Name;
522
                                string value = attribute.GetValue().ToString();
523
                                if (name == "DrawingItemType" && value == "LabelPersist")
524
                                {
525
                                    foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
526
                                    {
527
                                        if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
528
                                        {
529
                                            Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
530
                                            double prevX = _TargetItem.get_XCoordinate();
531
                                            double prevY = _TargetItem.get_YCoordinate();
532
                                            lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
533
                                            lineString2D.RemoveVertex(lineString2D.VertexCount);
534
                                            result = true;
535
                                            break;
536
                                        }
537
                                    }
538
                                }
539
540
                                if (result)
541
                                    break;
542
                            }
543
544
                            if (result)
545
                                break;
546
                        }
547
                    }
548
549
                    _LMLabelPresist.Commit();
550
                    ReleaseCOMObjects(_TargetItem);
551
                    ReleaseCOMObjects(_LMLabelPresist);
552
                }
553
            }
554
555
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
556
        }
557
558 74752074 gaqhf
        /// <summary>
559
        /// Equipment를 실제로 Modeling 메서드
560
        /// </summary>
561
        /// <param name="equipment"></param>
562 b9e9f4c8 gaqhf
        private void EquipmentModeling(Equipment equipment)
563
        {
564
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
565
                return;
566
567
            LMSymbol _LMSymbol = null;
568
            LMSymbol targetItem = null;
569
            string mappingPath = equipment.SPPID.MAPPINGNAME;
570
            double x = equipment.SPPID.ORIGINAL_X;
571
            double y = equipment.SPPID.ORIGINAL_Y;
572
            int mirror = 0;
573
            double angle = equipment.ANGLE;
574
575
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
576
            if (connector != null)
577
            {
578
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
579
                if (connEquipment != null)
580
                {
581
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
582
                        EquipmentModeling(connEquipment);
583
584
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
585
                    {
586
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
587
                        if (targetItem != null)
588
                        {
589
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
590
                        }
591
                        else
592
                        {
593
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
594
                        }
595
                    }
596
                    else
597
                    {
598
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
599
                    }
600
                }
601
                else
602
                {
603
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
604
                }
605
            }
606
            else
607
            {
608
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
609
            }
610
611
            if (_LMSymbol != null)
612
            {
613
                _LMSymbol.Commit();
614
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
615
                ReleaseCOMObjects(_LMSymbol);
616
            }
617
618
            if (targetItem != null)
619
            {
620
                ReleaseCOMObjects(targetItem);
621
            }
622
            
623
            ReleaseCOMObjects(_LMSymbol);
624 f31645b6 gaqhf
625
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
626 b9e9f4c8 gaqhf
        }
627
628 74752074 gaqhf
        /// <summary>
629
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
630
        /// </summary>
631
        /// <param name="childSymbol"></param>
632
        /// <param name="parentSymbol"></param>
633 4b4dbca9 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
634 ac78b508 gaqhf
        {
635 4b4dbca9 gaqhf
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
636
            double x1 = 0;
637
            double x2 = 0;
638
            double y1 = 0;
639
            double y2 = 0;
640
            symbol2d.Range(out x1, out y1, out x2, out y2);
641
642
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
643
            if (_LMSymbol != null)
644
            {
645
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
646
                foreach (var item in childSymbol.ChildSymbols)
647
                    CreateChildSymbol(item, _LMSymbol);
648
            }
649
            
650 ac78b508 gaqhf
651
            ReleaseCOMObjects(_LMSymbol);
652
        }
653
654 74752074 gaqhf
        /// <summary>
655
        /// item이 TargetItem과 같은 LineRun에 있는지 검사
656
        /// </summary>
657
        /// <param name="item"></param>
658
        /// <param name="targetItem"></param>
659
        /// <returns></returns>
660
        private bool IsSameLineRun(object item, object targetItem)
661 809a7640 gaqhf
        {
662
            foreach (var lineNumber in document.LINENUMBERS)
663
            {
664
                foreach (var run in lineNumber.RUNS)
665
                {
666
                    foreach (var runItem in run.RUNITEMS)
667
                    {
668
                        if (runItem == item)
669
                        {
670
                            foreach (var findItem in run.RUNITEMS)
671
                            {
672
                                if (findItem == targetItem)
673
                                {
674
                                    return true;
675
                                }
676
                            }
677
678
                            return false;
679
680
                        }
681
                    }
682
                }
683
            }
684
685
            return false;
686
        }
687
688 74752074 gaqhf
        /// <summary>
689
        /// Line을 실제로 모델링하는 메서드
690
        /// </summary>
691
        /// <param name="lines"></param>
692 1b261371 gaqhf
        private void LineModeling(List<Line> lines)
693
        {
694 335b7a24 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
695 1b261371 gaqhf
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
696 f1c9dbaa gaqhf
            LMSymbol _LMSymbol1 = null;
697
            LMSymbol _LMSymbol2 = null;
698 5e6ecf05 gaqhf
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
699
            LMConnector targetConnector1 = null;
700
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
701
            LMConnector targetConnector2 = null;
702 335b7a24 gaqhf
703
            Line startBranchLine = null;
704
            Line endBranchLine = null;
705
706 1b261371 gaqhf
            for (int i = 0; i < lines.Count; i++)
707
            {
708
                Line line = lines[i];
709 f1c9dbaa gaqhf
                if (i == 0 || i + 1 != lines.Count)
710
                {
711 809a7640 gaqhf
                    // 시작점에 연결된 Symbol 찾기
712 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
713
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
714
                    {
715 f2baa6a3 gaqhf
                        _LMSymbol1 = GetTargetSymbol(connItem as Symbol, line);
716 f1c9dbaa gaqhf
                        if (_LMSymbol1 != null)
717
                            placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y);
718
                        else
719
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
720
                    }
721 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
722 5e6ecf05 gaqhf
                    {
723
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
724 56bc67e1 gaqhf
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
725 5e6ecf05 gaqhf
726
                        if (targetConnector1 != null)
727
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
728
                        else
729 335b7a24 gaqhf
                        {
730
                            startBranchLine = connItem as Line;
731 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
732 335b7a24 gaqhf
                        }
733 5e6ecf05 gaqhf
                    }
734 f1c9dbaa gaqhf
                    else
735
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
736
                }
737
738
                if (i + 1 == lines.Count)
739
                {
740 809a7640 gaqhf
                    // 끝점에 연결된 Symbol 찾기
741 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
742 5e6ecf05 gaqhf
743
                    if (i != 0)
744
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
745
746 f1c9dbaa gaqhf
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
747
                    {
748 f2baa6a3 gaqhf
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
749 f1c9dbaa gaqhf
                        if (_LMSymbol2 != null)
750
                            placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y);
751
                        else
752
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
753
                            
754
                    }
755 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
756 5e6ecf05 gaqhf
                    {
757
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
758 56bc67e1 gaqhf
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
759 5e6ecf05 gaqhf
760
                        if (targetConnector2 != null)
761
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
762
                        else
763 335b7a24 gaqhf
                        {
764
                            endBranchLine = connItem as Line;
765 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
766 335b7a24 gaqhf
                        }
767 5e6ecf05 gaqhf
                    }
768 f1c9dbaa gaqhf
                    else
769
                    {
770
                        placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
771
                    }
772
                }
773
            }
774
775
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
776 335b7a24 gaqhf
777 f1c9dbaa gaqhf
            if (_lMConnector != null)
778
            {
779
                foreach (var line in lines)
780 5e6ecf05 gaqhf
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
781 f1c9dbaa gaqhf
                _lMConnector.Commit();
782 335b7a24 gaqhf
                if (startBranchLine != null || endBranchLine != null)
783
                {
784 3165c259 gaqhf
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
785 335b7a24 gaqhf
                }
786 1b261371 gaqhf
            }
787 5e6ecf05 gaqhf
788 1b261371 gaqhf
789 f1c9dbaa gaqhf
            if (_LMSymbol1 != null)
790
                ReleaseCOMObjects(_LMSymbol1);
791
            if (_LMSymbol2 != null)
792
                ReleaseCOMObjects(_LMSymbol2);
793 5e6ecf05 gaqhf
            if (targetConnector1 != null)
794
                ReleaseCOMObjects(targetConnector1);
795
            if (targetConnector2 != null)
796
                ReleaseCOMObjects(targetConnector2);
797
            foreach (var item in connectorVertices1)
798
                ReleaseCOMObjects(item.Key);
799
            foreach (var item in connectorVertices2)
800
                ReleaseCOMObjects(item.Key);
801 1b261371 gaqhf
802 f1c9dbaa gaqhf
            ReleaseCOMObjects(_lMConnector);
803 1b261371 gaqhf
            ReleaseCOMObjects(placeRunInputs);
804
            ReleaseCOMObjects(_LMAItem);
805
        }
806
807 74752074 gaqhf
        /// <summary>
808
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
809
        /// </summary>
810
        /// <param name="symbol"></param>
811
        /// <param name="line"></param>
812
        /// <returns></returns>
813 f2baa6a3 gaqhf
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
814
        {
815
            LMSymbol _LMSymbol = null;
816
            foreach (var connector in symbol.CONNECTORS)
817
            {
818
                if (connector.CONNECTEDITEM == line.UID)
819
                {
820
                    if (connector.Index == 0)
821
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
822
                    else
823
                    {
824
                        ChildSymbol child = null;
825
                        foreach (var childSymbol in symbol.ChildSymbols)
826
                        {
827
                            if (childSymbol.Connectors.Contains(connector))
828
                                child = childSymbol;
829
                            else
830
                                child = GetChildSymbolByConnector(childSymbol, connector);
831
832
                            if (child != null)
833
                                break;
834
                        }
835
836
                        if (child != null)
837
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
838
                    }
839
840
                    break;  
841
                }
842
            }
843
844
            return _LMSymbol;
845
        }
846
847 74752074 gaqhf
        /// <summary>
848
        /// Connector를 가지고 있는 ChildSymbol Object 반환
849
        /// </summary>
850
        /// <param name="item"></param>
851
        /// <param name="connector"></param>
852
        /// <returns></returns>
853 f2baa6a3 gaqhf
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
854
        {
855
            foreach (var childSymbol in item.ChildSymbols)
856
            {
857
                if (childSymbol.Connectors.Contains(connector))
858
                    return childSymbol;
859
                else
860
                    return GetChildSymbolByConnector(childSymbol, connector);
861
            }
862
863
            return null;
864
        }
865
866 74752074 gaqhf
        /// <summary>
867
        /// Branch 라인을 다시 모델링하는 진입 메서드
868
        /// </summary>
869
        /// <param name="branch"></param>
870 335b7a24 gaqhf
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
871
        {
872
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
873
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
874
875 8b085570 gaqhf
            LMConnector _StartConnector = null;
876
            LMConnector _EndConnector = null;
877 335b7a24 gaqhf
            double lengthStart = double.MaxValue;
878
            double lengthEnd = double.MaxValue;
879
            List<double[]> startPoints = new List<double[]>();
880
            List<double[]> endPoints = new List<double[]>();
881
882
            foreach (var item in connectorVertices)
883
            {
884
                foreach (var point in item.Value)
885
                {
886
                    // Start Point가 Branch
887
                    if (branch.Item2 != null)
888
                    {
889
                        Line targetLine = branch.Item2;
890
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
891
                        if (lengthStart > distance)
892
                        {
893 8b085570 gaqhf
                            _StartConnector = item.Key;
894 335b7a24 gaqhf
                            lengthStart = distance;
895
                            startPoints = item.Value;
896
                        }
897
                    }
898
                    // End Point가 Branch
899
                    if (branch.Item3 != null)
900
                    {
901
                        Line targetLine = branch.Item3;
902
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
903
                        if (lengthEnd > distance)
904
                        {
905 8b085570 gaqhf
                            _EndConnector = item.Key;
906 335b7a24 gaqhf
                            lengthEnd = distance;
907
                            endPoints = item.Value;
908
                        }
909
                    }
910
                }
911
            }
912
            #region Branch가 양쪽 전부일 때
913 8b085570 gaqhf
            if (_StartConnector != null && _StartConnector == _EndConnector)
914 335b7a24 gaqhf
            {
915 8b085570 gaqhf
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
916 335b7a24 gaqhf
917
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
918
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
919
920
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
921 8b085570 gaqhf
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
922 335b7a24 gaqhf
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
923 8b085570 gaqhf
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
924 335b7a24 gaqhf
                   startPoints[startPoints.Count - 1][0],
925
                   startPoints[startPoints.Count - 1][1],
926
                   startPoints[startPoints.Count - 2][0],
927
                   startPoints[startPoints.Count - 2][1]);
928
929
                for (int i = 0; i < startPoints.Count; i++)
930
                {
931
                    double[] point = startPoints[i];
932
                    if (i == 0)
933 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
934 335b7a24 gaqhf
                    else if (i == startPoints.Count - 1)
935 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
936 335b7a24 gaqhf
                    else
937
                        placeRunInputs.AddPoint(point[0], point[1]);
938
                }
939
940
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
941
                if (_LMConnector != null)
942
                {
943
                    _LMConnector.Commit();
944
                    foreach (var item in lines)
945
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
946
                }
947
948
                foreach (var item in startConnectorVertices)
949
                    ReleaseCOMObjects(item.Key);
950
                foreach (var item in endConnectorVertices)
951
                    ReleaseCOMObjects(item.Key);
952
                ReleaseCOMObjects(placeRunInputs);
953
                ReleaseCOMObjects(_LMAItem);
954
                ReleaseCOMObjects(_LMConnector);
955
            }
956
            #endregion
957 8b085570 gaqhf
            #region 양쪽이 다른 Branch 
958 335b7a24 gaqhf
            else
959
            {
960
                // Branch 시작 Connector
961 8b085570 gaqhf
                if (_StartConnector != null)
962 6b298450 gaqhf
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
963 335b7a24 gaqhf
964 6b298450 gaqhf
                // Branch 끝 Connector
965
                if (_EndConnector != null)
966
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
967
            }
968
            #endregion
969 335b7a24 gaqhf
970 6b298450 gaqhf
            if (_StartConnector != null)
971
                ReleaseCOMObjects(_StartConnector);
972
            if (_EndConnector != null)
973
                ReleaseCOMObjects(_EndConnector);
974
            foreach (var item in connectorVertices)
975
                ReleaseCOMObjects(item.Key);
976
        }
977 335b7a24 gaqhf
978 74752074 gaqhf
        /// <summary>
979
        /// Branch 라인을 다시 실제로 모델링하는 메서드
980
        /// </summary>
981
        /// <param name="branch"></param>
982
        /// <param name="_Connector"></param>
983
        /// <param name="points"></param>
984
        /// <param name="IsStart"></param>
985 6b298450 gaqhf
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
986
        {
987
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
988
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
989
            LMConnector _SameRunTargetConnector = null;
990
            LMSymbol _SameRunTargetSymbol = null;
991
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
992
            LMConnector _BranchTargetConnector = null;
993
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
994 335b7a24 gaqhf
995 6b298450 gaqhf
            // 같은 Line Run의 Connector 찾기
996
            foreach (var item in connectorVertices)
997
            {
998
                if (item.Key == _Connector)
999
                    continue;
1000 335b7a24 gaqhf
1001 6b298450 gaqhf
                if (IsStart &&
1002
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
1003
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
1004
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
1005
                {
1006
                    _SameRunTargetConnector = item.Key;
1007
                    break;
1008
                }
1009
                else if (!IsStart &&
1010
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
1011
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
1012
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
1013
                {
1014
                    _SameRunTargetConnector = item.Key;
1015
                    break;
1016
                }
1017
            }
1018
1019
            // Branch 반대편이 Symbol
1020
            if (_SameRunTargetConnector == null)
1021
            {
1022
                foreach (var line in lines)
1023
                {
1024
                    foreach (var connector in line.CONNECTORS)
1025 335b7a24 gaqhf
                    {
1026 6b298450 gaqhf
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
1027
                        if (symbol != null)
1028 335b7a24 gaqhf
                        {
1029 6b298450 gaqhf
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1030
                            break;
1031 335b7a24 gaqhf
                        }
1032
                    }
1033 6b298450 gaqhf
                }
1034
            }
1035 335b7a24 gaqhf
1036 6b298450 gaqhf
            // 기존 Connector 제거
1037
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
1038
            
1039
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
1040
            if (IsStart)
1041
            {
1042
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1043
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
1044
            }
1045
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
1046
            else
1047
            {
1048
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1049
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
1050
                    points[points.Count - 1][0],
1051
                    points[points.Count - 1][1],
1052
                    points[points.Count - 2][0],
1053
                    points[points.Count - 2][1]);
1054
            }
1055 335b7a24 gaqhf
1056 6b298450 gaqhf
            for (int i = 0; i < points.Count; i++)
1057
            {
1058
                double[] point = points[i];
1059
                if (i == 0)
1060 335b7a24 gaqhf
                {
1061 6b298450 gaqhf
                    if (IsStart)
1062 335b7a24 gaqhf
                    {
1063 6b298450 gaqhf
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1064 335b7a24 gaqhf
                    }
1065 6b298450 gaqhf
                    else
1066 335b7a24 gaqhf
                    {
1067 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
1068
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1069 65a1ed4b gaqhf
                        else if (_SameRunTargetSymbol != null)
1070 6b298450 gaqhf
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1071
                        else
1072
                            placeRunInputs.AddPoint(point[0], point[1]);
1073 335b7a24 gaqhf
                    }
1074 6b298450 gaqhf
                }
1075
                else if (i == points.Count - 1)
1076
                {
1077
                    if (IsStart)
1078 335b7a24 gaqhf
                    {
1079 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
1080
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1081
                        else if (_SameRunTargetSymbol != null)
1082
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1083 335b7a24 gaqhf
                        else
1084
                            placeRunInputs.AddPoint(point[0], point[1]);
1085
                    }
1086 6b298450 gaqhf
                    else
1087 335b7a24 gaqhf
                    {
1088 f9125a54 gaqhf
                        if (_BranchTargetConnector != null)
1089
                        {
1090
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1091
                        }
1092 335b7a24 gaqhf
                    }
1093 6b298450 gaqhf
                }
1094
                else
1095
                    placeRunInputs.AddPoint(point[0], point[1]);
1096
            }
1097
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1098
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1099 335b7a24 gaqhf
1100 6b298450 gaqhf
            if (_LMConnector != null)
1101
            {
1102
                if (_SameRunTargetConnector != null)
1103
                {
1104
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
1105
                }
1106
                else
1107
                {
1108
                    foreach (var item in lines)
1109
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1110 335b7a24 gaqhf
                }
1111
1112 6b298450 gaqhf
                _LMConnector.Commit();
1113
                ReleaseCOMObjects(_LMConnector);
1114 335b7a24 gaqhf
            }
1115
1116 6b298450 gaqhf
            ReleaseCOMObjects(placeRunInputs);
1117
            ReleaseCOMObjects(_LMAItem);
1118
            if (_BranchTargetConnector != null)
1119
                ReleaseCOMObjects(_BranchTargetConnector);
1120
            if (_SameRunTargetConnector != null)
1121
                ReleaseCOMObjects(_SameRunTargetConnector);
1122
            if (_SameRunTargetSymbol != null)
1123
                ReleaseCOMObjects(_SameRunTargetSymbol);
1124 335b7a24 gaqhf
            foreach (var item in connectorVertices)
1125
                ReleaseCOMObjects(item.Key);
1126 6b298450 gaqhf
            foreach (var item in branchConnectorVertices)
1127
                ReleaseCOMObjects(item.Key);
1128 335b7a24 gaqhf
        }
1129
1130 74752074 gaqhf
        /// <summary>
1131
        /// EndBreak 모델링 메서드
1132
        /// </summary>
1133
        /// <param name="endBreak"></param>
1134 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
1135 335b7a24 gaqhf
        {
1136 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
1137 2a4872ec gaqhf
            LMConnector targetLMConnector = null;
1138 10c7195c gaqhf
            if (ownerObj !=null && ownerObj.GetType() == typeof(Line))
1139 335b7a24 gaqhf
            {
1140 10c7195c gaqhf
                Line ownerLine = ownerObj as Line;
1141 3165c259 gaqhf
                LMLabelPersist _LmLabelPersist = null;
1142 ac78b508 gaqhf
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
1143 3165c259 gaqhf
1144 2a4872ec gaqhf
                targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1145 b9e9f4c8 gaqhf
                
1146 2a4872ec gaqhf
                if (targetLMConnector != null)
1147 335b7a24 gaqhf
                {
1148 ac78b508 gaqhf
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1149 2a4872ec gaqhf
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1150 ac78b508 gaqhf
                }
1151 3165c259 gaqhf
1152 ac78b508 gaqhf
                if (_LmLabelPersist != null)
1153
                {
1154
                    _LmLabelPersist.Commit();
1155
                    ReleaseCOMObjects(_LmLabelPersist);
1156 335b7a24 gaqhf
                }
1157 b9e9f4c8 gaqhf
                else
1158 2a4872ec gaqhf
                    RetryEndBreakModeling(endBreak, targetLMConnector);
1159 b9e9f4c8 gaqhf
1160 ac78b508 gaqhf
                foreach (var item in connectorVertices)
1161
                    ReleaseCOMObjects(item.Key);
1162 2a4872ec gaqhf
1163 335b7a24 gaqhf
            }
1164 10c7195c gaqhf
            else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol))
1165
            {
1166
                Symbol ownerSymbol = ownerObj as Symbol;
1167
                LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId);
1168
1169 2a4872ec gaqhf
                targetLMConnector = null;
1170 10c7195c gaqhf
                double distance = double.MaxValue;
1171 b9e9f4c8 gaqhf
1172 10c7195c gaqhf
                foreach (LMConnector connector in _LMSymbol.Avoid1Connectors)
1173
                {
1174 26c6f818 gaqhf
                    if (connector.get_ItemStatus() == "Active")
1175 10c7195c gaqhf
                    {
1176 26c6f818 gaqhf
                        dynamic OID = connector.get_GraphicOID();
1177
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1178
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1179
                        int verticesCount = lineStringGeometry.VertexCount;
1180
                        double[] vertices = null;
1181
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1182
                        for (int i = 0; i < verticesCount; i++)
1183 10c7195c gaqhf
                        {
1184 26c6f818 gaqhf
                            double x = 0;
1185
                            double y = 0;
1186
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1187
1188 b9e9f4c8 gaqhf
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1189 26c6f818 gaqhf
                            if (result < distance)
1190
                            {
1191
                                targetLMConnector = connector;
1192
                                distance = result;
1193
                            }
1194 10c7195c gaqhf
                        }
1195
                    }
1196
                }
1197
1198
                foreach (LMConnector connector in _LMSymbol.Avoid2Connectors)
1199
                {
1200 b9e9f4c8 gaqhf
                    if (connector.get_ItemStatus() == "Active")
1201 10c7195c gaqhf
                    {
1202 b9e9f4c8 gaqhf
                        dynamic OID = connector.get_GraphicOID();
1203
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1204
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1205
                        int verticesCount = lineStringGeometry.VertexCount;
1206
                        double[] vertices = null;
1207
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1208
                        for (int i = 0; i < verticesCount; i++)
1209 10c7195c gaqhf
                        {
1210 b9e9f4c8 gaqhf
                            double x = 0;
1211
                            double y = 0;
1212
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1213
1214
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1215
                            if (result < distance)
1216
                            {
1217
                                targetLMConnector = connector;
1218
                                distance = result;
1219
                            }
1220 10c7195c gaqhf
                        }
1221
                    }
1222
                }
1223
1224
                if (targetLMConnector != null)
1225
                {
1226
                    LMLabelPersist _LmLabelPersist = null;
1227
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1228
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1229
                    if (_LmLabelPersist != null)
1230
                    {
1231
                        _LmLabelPersist.Commit();
1232
                        ReleaseCOMObjects(_LmLabelPersist);
1233
                    }
1234 b9e9f4c8 gaqhf
                    else
1235 2a4872ec gaqhf
                        RetryEndBreakModeling(endBreak, targetLMConnector);
1236
                }
1237
                
1238
                ReleaseCOMObjects(_LMSymbol);
1239
            }
1240 f31645b6 gaqhf
1241
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1242 2a4872ec gaqhf
        }
1243 b9e9f4c8 gaqhf
1244 74752074 gaqhf
        /// <summary>
1245
        /// EndBreak 모델링이 실패시 다시 시도하는 메서드
1246
        /// </summary>
1247
        /// <param name="endBreak"></param>
1248
        /// <param name="targetLMConnector"></param>
1249 2a4872ec gaqhf
        private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector)
1250
        {
1251
            bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength());
1252
            Array array = null;
1253
            LMLabelPersist _LMLabelPersist = null;
1254
            LMConnector _LMConnector = null;
1255
            dynamic OID = targetLMConnector.get_GraphicOID();
1256
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1257
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1258
            int verticesCount = lineStringGeometry.VertexCount;
1259
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1260
            _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym");
1261 b9e9f4c8 gaqhf
1262 2a4872ec gaqhf
            if (isZeroLength)
1263
            {
1264
                double[] vertices = null;
1265
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1266
                double x = 0;
1267
                double y = 0;
1268
                lineStringGeometry.GetVertex(1, ref x, ref y);
1269 b9e9f4c8 gaqhf
1270 2a4872ec gaqhf
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y);
1271
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y);
1272 b9e9f4c8 gaqhf
1273 2a4872ec gaqhf
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1274
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1275
1276
                array = new double[] { 0, x, y };
1277
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1278 5a83fda2 gaqhf
1279
                AutoJoinPipeRun(_LMConnector.ModelItemID);
1280 2a4872ec gaqhf
            }
1281
            else
1282
            {
1283
                List<double[]> vertices = new List<double[]>();
1284
                for (int i = 1; i <= verticesCount; i++)
1285
                {
1286
                    double x = 0;
1287
                    double y = 0;
1288
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1289
                    vertices.Add(new double[] { x, y });
1290
                }
1291
1292
                for (int i = 0; i < vertices.Count; i++)
1293
                {
1294
                    double[] points = vertices[i];
1295
                    if (i == 0)
1296
                    {
1297
                        if (targetLMConnector.ConnectItem1SymbolObject != null)
1298
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1299
                        else
1300
                            placeRunInputs.AddPoint(points[0], points[1]);
1301 b9e9f4c8 gaqhf
                    }
1302 2a4872ec gaqhf
                    else if (i == vertices.Count - 1)
1303
                    {
1304
                        if (targetLMConnector.ConnectItem2SymbolObject != null)
1305
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1306
                        else
1307
                            placeRunInputs.AddPoint(points[0], points[1]);
1308
                    }
1309
                    else
1310
                        placeRunInputs.AddPoint(points[0], points[1]);
1311 10c7195c gaqhf
                }
1312 2a4872ec gaqhf
1313
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID);
1314 b9e9f4c8 gaqhf
                
1315 2a4872ec gaqhf
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1316
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1317
1318
                array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1319
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1320 3939eebf gaqhf
1321
                AutoJoinPipeRun(_LMConnector.ModelItemID);
1322
                foreach (var line in lines)
1323
                    line.SPPID.ModelItemId = _LMConnector.ModelItemID;
1324 10c7195c gaqhf
            }
1325 2a4872ec gaqhf
1326
1327
            if (_LMLabelPersist != null)
1328
            {
1329
                _LMLabelPersist.Commit();
1330
                ReleaseCOMObjects(_LMLabelPersist);
1331
            }
1332
            else
1333
            {
1334
                
1335
            }
1336
1337
            ReleaseCOMObjects(_LMConnector);
1338
            ReleaseCOMObjects(placeRunInputs);
1339
            ReleaseCOMObjects(_LMAItem);
1340 3165c259 gaqhf
        }
1341 10872260 gaqhf
1342 74752074 gaqhf
        /// <summary>
1343
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
1344
        /// </summary>
1345
        /// <param name="fromModelItemId"></param>
1346
        /// <param name="toModelItemId"></param>
1347 335b7a24 gaqhf
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
1348
        {
1349 310aeb31 gaqhf
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
1350
            _LMAItem item1 = modelItem1.AsLMAItem();
1351
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
1352
            _LMAItem item2 = modelItem2.AsLMAItem();
1353
            
1354 335b7a24 gaqhf
            // item2가 item1으로 조인
1355
            try
1356
            {
1357
                _placement.PIDJoinRuns(ref item1, ref item2);
1358 65a1ed4b gaqhf
                item1.Commit();
1359
                item2.Commit();
1360 3939eebf gaqhf
1361
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
1362
                foreach (var line in lines)
1363
                    line.SPPID.ModelItemId = toModelItemId;
1364 335b7a24 gaqhf
            }
1365
            catch (Exception ex)
1366
            {
1367
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1368
            }
1369
            finally
1370
            {
1371 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem1);
1372
                ReleaseCOMObjects(item1);
1373
                ReleaseCOMObjects(modelItem2);
1374
                ReleaseCOMObjects(item2);
1375 335b7a24 gaqhf
            }
1376
        }
1377
1378 74752074 gaqhf
        /// <summary>
1379
        /// PipeRun을 자동으로 Join하는 메서드
1380
        /// </summary>
1381
        /// <param name="modelItemId"></param>
1382 335b7a24 gaqhf
        private void AutoJoinPipeRun(string modelItemId)
1383
        {
1384 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
1385
            _LMAItem item = modelItem.AsLMAItem();
1386 65a1ed4b gaqhf
            try
1387
            {
1388
                string modelitemID = item.Id;
1389
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
1390
                string afterModelItemID = item.Id;
1391 5a83fda2 gaqhf
                
1392 65a1ed4b gaqhf
                if (modelitemID != afterModelItemID)
1393
                {
1394
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
1395
                    foreach (var line in lines)
1396
                        line.SPPID.ModelItemId = afterModelItemID;
1397
                }
1398
                item.Commit();
1399
            }
1400
            catch (Exception ex)
1401
            {
1402
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1403
            }
1404
            finally
1405
            {
1406 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
1407
                ReleaseCOMObjects(item);
1408 65a1ed4b gaqhf
            }
1409 335b7a24 gaqhf
        }
1410
1411 74752074 gaqhf
        /// <summary>
1412
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
1413
        /// </summary>
1414
        /// <param name="run"></param>
1415 335b7a24 gaqhf
        private void JoinRunLine(LineRun run)
1416
        {
1417
            string modelItemId = string.Empty;
1418
            foreach (var item in run.RUNITEMS)
1419
            {
1420
                if (item.GetType() == typeof(Line))
1421
                {
1422
                    Line line = item as Line;
1423 1ba9c671 gaqhf
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
1424
                    modelItemId = line.SPPID.ModelItemId;
1425 f31645b6 gaqhf
1426
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1427 335b7a24 gaqhf
                }
1428
            }
1429
        }
1430
1431 74752074 gaqhf
        /// <summary>
1432
        /// PipeRun의 좌표를 가져오는 메서드
1433
        /// </summary>
1434
        /// <param name="modelId"></param>
1435
        /// <returns></returns>
1436 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
1437
        {
1438
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
1439 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
1440
1441
            if (modelItem != null)
1442 5e6ecf05 gaqhf
            {
1443 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
1444 5e6ecf05 gaqhf
                {
1445
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1446
                    {
1447
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1448
                        connectorVertices.Add(_LMConnector, new List<double[]>());
1449
                        dynamic OID = rep.get_GraphicOID();
1450 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1451 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1452
                        int verticesCount = lineStringGeometry.VertexCount;
1453
                        double[] vertices = null;
1454
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1455
                        for (int i = 0; i < verticesCount; i++)
1456
                        {
1457
                            double x = 0;
1458
                            double y = 0;
1459
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1460 335b7a24 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
1461 5e6ecf05 gaqhf
                        }
1462
                    }
1463
                }
1464
1465 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
1466 5e6ecf05 gaqhf
            }
1467
1468
            return connectorVertices;
1469
        }
1470
1471 74752074 gaqhf
        /// <summary>
1472
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함
1473
        /// </summary>
1474
        /// <param name="connectorVertices"></param>
1475
        /// <param name="connX"></param>
1476
        /// <param name="connY"></param>
1477
        /// <param name="x2"></param>
1478
        /// <param name="y2"></param>
1479
        /// <returns></returns>
1480 56bc67e1 gaqhf
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
1481 5e6ecf05 gaqhf
        {
1482
            double length = double.MaxValue;
1483
            LMConnector targetConnector = null;
1484
            foreach (var item in connectorVertices)
1485
            {
1486
                List<double[]> points = item.Value;
1487
                for (int i = 0; i < points.Count - 1; i++)
1488
                {
1489
                    double[] point1 = points[i];
1490
                    double[] point2 = points[i + 1];
1491
1492 335b7a24 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
1493
                    double minLineX = Math.Min(point1[0], point2[0]);
1494
                    double maxLineY = Math.Max(point1[1], point2[1]);
1495
                    double minLineY = Math.Min(point1[1], point2[1]);
1496
1497
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
1498
1499 56bc67e1 gaqhf
                    // 두직선의 교차점
1500
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
1501
                    if (crossingPoint != null)
1502 5e6ecf05 gaqhf
                    {
1503 30a9ffce gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
1504 335b7a24 gaqhf
                        if (length >= distance)
1505 30a9ffce gaqhf
                        {
1506 335b7a24 gaqhf
                            if (slope == SlopeType.Slope &&
1507
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
1508
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1509
                            {
1510
                                targetConnector = item.Key;
1511
                                length = distance;
1512
                            }
1513
                            else if (slope == SlopeType.HORIZONTAL &&
1514
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
1515
                            {
1516
                                targetConnector = item.Key;
1517
                                length = distance;
1518
                            }
1519
                            else if (slope == SlopeType.VERTICAL &&
1520
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1521
                            {
1522
                                targetConnector = item.Key;
1523
                                length = distance;
1524
                            }
1525 30a9ffce gaqhf
                        }
1526 5e6ecf05 gaqhf
                    }
1527
                }
1528 c3d2e266 gaqhf
1529
1530
            }
1531
1532
            if (targetConnector == null)
1533
            {
1534
                foreach (var item in connectorVertices)
1535
                {
1536
                    List<double[]> points = item.Value;
1537
                    foreach (var point in points)
1538
                    {
1539
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
1540
                        if (length >= distance)
1541
                        {
1542
                            targetConnector = item.Key;
1543
                            length = distance;
1544
                        }
1545
                    }
1546
                }
1547
1548 5e6ecf05 gaqhf
            }
1549
1550
            return targetConnector;
1551
        }
1552
1553 74752074 gaqhf
        /// <summary>
1554
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순)
1555
        /// </summary>
1556
        /// <param name="connectorVertices"></param>
1557
        /// <param name="connX"></param>
1558
        /// <param name="connY"></param>
1559
        /// <returns></returns>
1560 ac78b508 gaqhf
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1561
        {
1562
            double length = double.MaxValue;
1563
            LMConnector targetConnector = null;
1564
            foreach (var item in connectorVertices)
1565
            {
1566
                List<double[]> points = item.Value;
1567
1568
                foreach (double[] point in points)
1569
                {
1570
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1571
                    if (length >= distance)
1572
                    {
1573
                        targetConnector = item.Key;
1574
                        length = distance;
1575
                    }
1576
                }
1577
            }
1578
1579
            return targetConnector;
1580
        }
1581
1582 74752074 gaqhf
        /// <summary>
1583
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
1584
        /// </summary>
1585
        /// <param name="connectorVertices"></param>
1586
        /// <param name="connX"></param>
1587
        /// <param name="connY"></param>
1588
        /// <returns></returns>
1589 68464385 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1590
        {
1591
            double length = double.MaxValue;
1592
            LMConnector targetConnector = null;
1593
            foreach (var item in connectorVertices)
1594
            {
1595
                List<double[]> points = item.Value;
1596
                for (int i = 0; i < points.Count - 1; i++)
1597
                {
1598
                    double[] point1 = points[i];
1599
                    double[] point2 = points[i + 1];
1600
                    double x1 = Math.Min(point1[0], point2[0]);
1601
                    double y1 = Math.Min(point1[1], point2[1]);
1602
                    double x2 = Math.Max(point1[0], point2[0]);
1603
                    double y2 = Math.Max(point1[1], point2[1]);
1604
1605
                    if ((x1 <= connX && x2 >= connX) ||
1606
                        (y1 <= connY && y2 >= connY))
1607
                    {
1608
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
1609
                        if (length >= distance)
1610
                        {
1611
                            targetConnector = item.Key;
1612
                            length = distance;
1613
                        }
1614
1615
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
1616
                        if (length >= distance)
1617
                        {
1618
                            targetConnector = item.Key;
1619
                            length = distance;
1620
                        }
1621
                    }
1622
                }
1623
            }
1624
1625
            // 못찾았을때.
1626
            length = double.MaxValue;
1627
            if (targetConnector == null)
1628
            {
1629
                foreach (var item in connectorVertices)
1630
                {
1631
                    List<double[]> points = item.Value;
1632
1633
                    foreach (double[] point in points)
1634
                    {
1635
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1636
                        if (length >= distance)
1637
                        {
1638
                            targetConnector = item.Key;
1639
                            length = distance;
1640
                        }
1641
                    }
1642
                }
1643
            }
1644
1645
            return targetConnector;
1646
        }
1647
1648 74752074 gaqhf
        /// <summary>
1649
        /// Line Number Symbol을 실제로 Modeling하는 메서드
1650
        /// </summary>
1651
        /// <param name="lineNumber"></param>
1652 cfda1fed gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
1653
        {
1654 f4880c6a gaqhf
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1655
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
1656 68464385 gaqhf
            LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
1657 f4880c6a gaqhf
            if (connectedLMConnector != null)
1658 10872260 gaqhf
            {
1659 b65a7e32 gaqhf
                double x = 0;
1660
                double y = 0;
1661
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
1662
1663
                Array points = new double[] { 0, x, y };
1664 f4880c6a gaqhf
                LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
1665 cfda1fed gaqhf
1666 f4880c6a gaqhf
                foreach (var item in connectorVertices)
1667
                    ReleaseCOMObjects(item.Key);
1668
                if (_LmLabelPresist != null)
1669
                {
1670 c3d2e266 gaqhf
                    _LmLabelPresist.Commit();
1671 f4880c6a gaqhf
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1672
                    ReleaseCOMObjects(_LmLabelPresist);
1673 10872260 gaqhf
                }
1674 c3d2e266 gaqhf
                else
1675
                {
1676
1677
                }
1678 10872260 gaqhf
            }
1679 f31645b6 gaqhf
1680
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1681 cfda1fed gaqhf
        }
1682
1683 74752074 gaqhf
        /// <summary>
1684
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
1685
        /// </summary>
1686
        /// <param name="lineNumber"></param>
1687 a7e9beec gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber)
1688
        {
1689 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
1690 a7e9beec gaqhf
            {
1691 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
1692 a7e9beec gaqhf
                {
1693 8634af60 gaqhf
                    if (item.GetType() == typeof(Symbol))
1694 a7e9beec gaqhf
                    {
1695 8634af60 gaqhf
                        Symbol symbol = item as Symbol;
1696
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1697
                        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1698
1699
                        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
1700
                        {
1701
                            foreach (var attribute in lineNumber.ATTRIBUTES)
1702
                            {
1703
                                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1704
                                if (mapping != null)
1705
                                {
1706
                                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1707
                                    if (_LMAAttribute != null)
1708
                                    {
1709
                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1710
                                            _LMAAttribute.set_Value(attribute.VALUE);
1711
                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
1712
                                            _LMAAttribute.set_Value(attribute.VALUE);
1713
                                    }
1714
                                }
1715
                            }
1716
                            _LMModelItem.Commit();
1717
                        }
1718
                        if (_LMModelItem != null)
1719
                            ReleaseCOMObjects(_LMModelItem);
1720
                        if (_LMSymbol != null)
1721
                            ReleaseCOMObjects(_LMSymbol);
1722
                    }
1723
                    else if (item.GetType() == typeof(Line))
1724
                    {
1725
                        Line line = item as Line;
1726
                        if (line != null)
1727 a7e9beec gaqhf
                        {
1728 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1729
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
1730 a7e9beec gaqhf
                            {
1731 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
1732
                                {
1733
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1734
                                    if (mapping != null)
1735
                                    {
1736
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1737
                                        if (_LMAAttribute != null)
1738
                                        {
1739
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1740
                                                _LMAAttribute.set_Value(attribute.VALUE);
1741
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
1742
                                                _LMAAttribute.set_Value(attribute.VALUE);
1743
                                            
1744
                                        }
1745
                                    }
1746
                                }
1747 68464385 gaqhf
                                _LMModelItem.Commit();
1748 a7e9beec gaqhf
                            }
1749 8634af60 gaqhf
                            if (_LMModelItem != null)
1750
                                ReleaseCOMObjects(_LMModelItem);
1751 a7e9beec gaqhf
                        }
1752
                    }
1753
                }
1754
            }
1755 f31645b6 gaqhf
1756
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1757 a7e9beec gaqhf
        }
1758
1759 74752074 gaqhf
        /// <summary>
1760
        /// Symbol Attribute 입력 메서드
1761
        /// </summary>
1762 73415441 gaqhf
        /// <param name="item"></param>
1763
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
1764 1efc25a3 gaqhf
        {
1765 ac78b508 gaqhf
            try
1766 1efc25a3 gaqhf
            {
1767 73415441 gaqhf
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
1768
                string sRep = null;
1769
                if (targetItem.GetType() == typeof(Symbol))
1770
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1771
                else if (targetItem.GetType() == typeof(Equipment))
1772
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1773
                    
1774
                if (!string.IsNullOrEmpty(sRep))
1775 402ef5b1 gaqhf
                {
1776 73415441 gaqhf
                    LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
1777 310aeb31 gaqhf
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1778 ea80efaa gaqhf
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
1779 402ef5b1 gaqhf
1780 73415441 gaqhf
                    foreach (var item in targetAttributes)
1781 65a1ed4b gaqhf
                    {
1782 ac78b508 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1783 26c6f818 gaqhf
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
1784 ac78b508 gaqhf
                        {
1785
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1786
                            if (_Attribute != null)
1787 73415441 gaqhf
                                _Attribute.set_Value(item.VALUE);
1788 ac78b508 gaqhf
                        }
1789 65a1ed4b gaqhf
                    }
1790 73415441 gaqhf
                    _LMModelItem.Commit();
1791
                    
1792 ea80efaa gaqhf
                    ReleaseCOMObjects(_Attributes);
1793
                    ReleaseCOMObjects(_LMModelItem);
1794 73415441 gaqhf
                    ReleaseCOMObjects(_LMSymbol);
1795 ac78b508 gaqhf
                }
1796
            }
1797
            catch (Exception ex)
1798
            {
1799
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1800 1efc25a3 gaqhf
            }
1801 f31645b6 gaqhf
1802
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1803 1efc25a3 gaqhf
        }
1804
1805 74752074 gaqhf
        /// <summary>
1806
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
1807
        /// </summary>
1808
        /// <param name="text"></param>
1809 cfda1fed gaqhf
        private void TextModeling(Text text)
1810
        {
1811 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
1812
            try
1813
            {
1814 8b069d9f gaqhf
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
1815
                if (text.ASSOCIATION)
1816 ea80efaa gaqhf
                {
1817
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
1818
                    if (owner.GetType() == typeof(Symbol))
1819
                    {
1820
                        Symbol symbol = owner as Symbol;
1821
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1822
                        if (_LMSymbol != null)
1823
                        {
1824
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
1825
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
1826
                            AttributeMapping mapping = null;
1827
                            foreach (var attribute in attributes)
1828
                            {
1829 26c6f818 gaqhf
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
1830
                                    continue;
1831
1832 ea80efaa gaqhf
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
1833
                                if (mapping != null)
1834
                                    break;  
1835
                            }
1836
1837
                            if (mapping != null)
1838
                            {
1839 1a3a74a8 gaqhf
                                double x = 0;
1840
                                double y = 0;
1841
1842 b65a7e32 gaqhf
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
1843
                                Array array = new double[] { 0, x, y };
1844 1a3a74a8 gaqhf
1845 1ba9c671 gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
1846 ea80efaa gaqhf
                                if (_LMLabelPersist!=null)
1847
                                {
1848 f9125a54 gaqhf
                                    _LMLabelPersist.Commit();
1849 ea80efaa gaqhf
                                    ReleaseCOMObjects(_LMLabelPersist);
1850
                                }
1851
                            }
1852
                        }
1853
                    }
1854
                    else if (owner.GetType() == typeof(Line))
1855
                    {
1856
1857
                    }
1858
                }
1859
                else
1860
                {
1861
                    LMItemNote _LMItemNote = null;
1862
                    LMAAttribute _LMAAttribute = null;
1863
1864 b65a7e32 gaqhf
                    double x = 0;
1865
                    double y = 0;
1866
1867
                    CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
1868
1869
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
1870 ea80efaa gaqhf
                    _LMSymbol.Commit();
1871
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1872
                    _LMItemNote.Commit();
1873
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1874
                    _LMAAttribute.set_Value(text.VALUE);
1875
                    _LMItemNote.Commit();
1876
1877
                    if (_LMAAttribute != null)
1878
                        ReleaseCOMObjects(_LMAAttribute);
1879
                    if (_LMItemNote != null)
1880
                        ReleaseCOMObjects(_LMItemNote);
1881
                }
1882 6b298450 gaqhf
            }
1883
            catch (Exception ex)
1884
            {
1885 cfda1fed gaqhf
1886 6b298450 gaqhf
            }
1887
            finally
1888
            {
1889
                if (_LMSymbol != null)
1890
                    ReleaseCOMObjects(_LMSymbol);
1891
            }
1892 f31645b6 gaqhf
1893
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1894 cfda1fed gaqhf
        }
1895
1896 74752074 gaqhf
        /// <summary>
1897
        /// Note Modeling
1898
        /// </summary>
1899
        /// <param name="note"></param>
1900 cfda1fed gaqhf
        private void NoteModeling(Note note)
1901
        {
1902 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
1903
            LMItemNote _LMItemNote = null;
1904
            LMAAttribute _LMAAttribute = null;
1905
1906
            try
1907
            {
1908 b65a7e32 gaqhf
                double x = 0;
1909
                double y = 0;
1910
1911
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
1912
1913
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
1914 6b298450 gaqhf
                _LMSymbol.Commit();
1915
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1916
                _LMItemNote.Commit();
1917
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1918
                _LMAAttribute.set_Value(note.VALUE);
1919
                _LMItemNote.Commit();
1920
            }
1921
            catch (Exception ex)
1922
            {
1923 cfda1fed gaqhf
1924 6b298450 gaqhf
            }
1925
            finally
1926
            {
1927
                if (_LMAAttribute != null)
1928
                    ReleaseCOMObjects(_LMAAttribute);
1929
                if (_LMItemNote != null)
1930
                    ReleaseCOMObjects(_LMItemNote);
1931
                if (_LMSymbol != null)
1932
                    ReleaseCOMObjects(_LMSymbol);
1933
            }
1934 f31645b6 gaqhf
1935
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1936 cfda1fed gaqhf
        }
1937
1938 74752074 gaqhf
        /// <summary>
1939
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
1940
        /// </summary>
1941
        /// <param name="x"></param>
1942
        /// <param name="y"></param>
1943
        /// <param name="originX"></param>
1944
        /// <param name="originY"></param>
1945
        /// <param name="SPPIDLabelLocation"></param>
1946
        /// <param name="location"></param>
1947 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
1948
        {
1949
            if (location == Location.None)
1950
            {
1951
                x = originX;
1952
                y = originY;
1953
            }
1954
            else
1955
            {
1956
                if (location.HasFlag(Location.Center))
1957
                {
1958
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
1959
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
1960
                }
1961
1962
                if (location.HasFlag(Location.Left))
1963
                    x = SPPIDLabelLocation.X1;
1964
                else if (location.HasFlag(Location.Right))
1965
                    x = SPPIDLabelLocation.X2;
1966
1967
                if (location.HasFlag(Location.Down))
1968
                    y = SPPIDLabelLocation.Y1;
1969
                else if (location.HasFlag(Location.Up))
1970
                    y = SPPIDLabelLocation.Y2;
1971
            }
1972
        }
1973 5a4b8f32 gaqhf
1974 74752074 gaqhf
        /// <summary>
1975
        /// ComObject를 Release
1976
        /// </summary>
1977
        /// <param name="objVars"></param>
1978 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
1979
        {
1980
            int intNewRefCount = 0;
1981
            foreach (object obj in objVars)
1982
            {
1983
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1984
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1985
            }
1986
        }
1987 cfda1fed gaqhf
    }
1988
}
클립보드 이미지 추가 (최대 크기: 500 MB)