프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 7c3cdd0b

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