프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ e8536f2b

이력 | 보기 | 이력해설 | 다운로드 (133 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 4d2571ab gaqhf
using System.Data;
7 cfda1fed gaqhf
using Llama;
8
using Plaice;
9 8aa6f2db gaqhf
using Ingr.RAD2D.Interop.RAD2D;
10
using Ingr.RAD2D.Internal;
11
using Ingr.RAD2D.Helper;
12 cfda1fed gaqhf
using Converter.BaseModel;
13
using Converter.SPPID.Model;
14
using Converter.SPPID.Properties;
15
using Converter.SPPID.Util;
16
using Converter.SPPID.DB;
17 5e6ecf05 gaqhf
using Ingr.RAD2D.MacroControls.CmdCtrl;
18
using Ingr.RAD2D;
19 5dfb8a24 gaqhf
using System.Windows;
20 cfda1fed gaqhf
using System.Threading;
21 5dfb8a24 gaqhf
using System.Drawing;
22 cfda1fed gaqhf
using Microsoft.VisualBasic;
23
using Newtonsoft.Json;
24
25 ca214bc3 gaqhf
using DevExpress.XtraSplashScreen;
26 cfda1fed gaqhf
namespace Converter.SPPID
27
{
28
    public class AutoModeling
29
    {
30 809a7640 gaqhf
        Placement _placement;
31
        LMADataSource dataSource;
32 1ba9c671 gaqhf
        dynamic newDrawing;
33 d19ae675 gaqhf
        dynamic application;
34 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
35 cfda1fed gaqhf
        SPPID_Document document;
36 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
37 f1c9dbaa gaqhf
38 d5ec4d0f gaqhf
        public string DocumentLabelText { get; set; }
39
40 f31645b6 gaqhf
        int CurrentCount;
41 69b7387a gaqhf
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42 47ad9a46 gaqhf
43 d19ae675 gaqhf
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
44 cfda1fed gaqhf
        {
45
            this.document = document;
46 d19ae675 gaqhf
            this.application = application;
47 5e6ecf05 gaqhf
            this.radApp = radApp;
48 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
49 cfda1fed gaqhf
        }
50
51 b265df51 gaqhf
        private int ClacProgressCount()
52 f31645b6 gaqhf
        {
53 b265df51 gaqhf
            int EquipCount = 0;
54
            int SymbolCount = 0;
55
            int LineCount = 0;
56
            int NoteCount = 0;
57
            int TextCount = 0;
58
            int EndBreakCount = 0;
59
            int LineNumberCount = 0;
60
61 f31645b6 gaqhf
            EquipCount = document.Equipments.Count;
62
            SymbolCount = document.SYMBOLS.Count;
63
            SymbolCount = SymbolCount * 3;
64
            
65
            foreach (LineNumber lineNumber in document.LINENUMBERS)
66
                foreach (LineRun run in lineNumber.RUNS)
67
                    foreach (var item in run.RUNITEMS)
68
                        if (item.GetType() == typeof(Line))
69
                            LineCount++;
70
            foreach (TrimLine trimLine in document.TRIMLINES)
71
                foreach (LineRun run in trimLine.RUNS)
72
                    foreach (var item in run.RUNITEMS)
73
                        if (item.GetType() == typeof(Line))
74
                            LineCount++;
75
76
            LineCount = LineCount * 2;
77
            NoteCount = document.NOTES.Count;
78
            TextCount = document.TEXTINFOS.Count;
79
            EndBreakCount = document.EndBreaks.Count;
80
            LineNumberCount = document.LINENUMBERS.Count;
81
            LineNumberCount = LineNumberCount * 2;
82
83 b265df51 gaqhf
            return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount;
84 f31645b6 gaqhf
        }
85
86 02480ac1 gaqhf
        private void SetSystemEditingCommand(bool value)
87
        {
88
            foreach (var item in radApp.Commands)
89
            {
90
                if (item.Argument == "SystemEditingCmd.SystemEditing")
91
                {
92
                    if (item.Checked != value)
93
                    {
94
                        radApp.RunMacro("systemeditingcmd.dll");
95
                        break;
96
                    }
97
98
                }
99
            }
100
        }
101
102 74752074 gaqhf
        /// <summary>
103
        /// 도면 단위당 실행되는 메서드
104
        /// </summary>
105 1ba9c671 gaqhf
        public void Run()
106 c2fef4ca gaqhf
        {
107 1ba9c671 gaqhf
            try
108 c2fef4ca gaqhf
            {
109 1ba9c671 gaqhf
                _placement = new Placement();
110
                dataSource = _placement.PIDDataSource;
111
112 0e0edfad gaqhf
                CreateDocument();
113 1ba9c671 gaqhf
114 0e0edfad gaqhf
                if (DocumentCoordinateCorrection())
115 310aeb31 gaqhf
                {
116 b265df51 gaqhf
                    int AllCount = ClacProgressCount();
117 3939eebf gaqhf
118 965eb728 gaqhf
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
119 20972c61 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount);
120
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
121 965eb728 gaqhf
122 4d2571ab gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Priority Symbol Modeling");
123
                    List<Symbol> prioritySymbols = GetPrioritySymbol();
124
                    foreach (var item in prioritySymbols)
125
                        SymbolModelingByPriority(item);
126 d1eac84d gaqhf
127 3939eebf gaqhf
                    // Equipment Modeling
128 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
129 3939eebf gaqhf
                    foreach (Equipment equipment in document.Equipments)
130
                        EquipmentModeling(equipment);
131
132
                    // LineRun Symbol Modeling
133 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling");
134 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
135
                        foreach (LineRun run in lineNumber.RUNS)
136
                            SymbolModelingByRun(run);
137
                    // TrimLineRun Symbol Modeling
138
                    foreach (TrimLine trimLine in document.TRIMLINES)
139
                        foreach (LineRun run in trimLine.RUNS)
140
                            SymbolModelingByRun(run);
141
142
                    // LineRun Line Modeling
143 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
144 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
145
                        foreach (LineRun run in lineNumber.RUNS)
146
                            LineModelingByRun(run);
147
                    // TrimLineRun Line Modeling
148
                    foreach (TrimLine trimLine in document.TRIMLINES)
149
                        foreach (LineRun run in trimLine.RUNS)
150
                            LineModelingByRun(run);
151
152
                    // Branch Line Modeling
153 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
154 3939eebf gaqhf
                    foreach (var item in BranchLines)
155
                        BranchLineModeling(item);
156
157
                    // EndBreak Modeling
158 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
159 3939eebf gaqhf
                    foreach (var item in document.EndBreaks)
160
                        EndBreakModeling(item);
161
162 53c81765 gaqhf
                    // SpecBreak Modeling
163
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
164
                    foreach (var item in document.SpecBreaks)
165
                        SpecBreakModeling(item);
166
167 3939eebf gaqhf
                    // LineNumber Modeling
168 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling");
169 3939eebf gaqhf
                    foreach (var item in document.LINENUMBERS)
170
                        LineNumberModeling(item);
171
172 b2d1c1aa gaqhf
                    // LineNumber Modeling
173
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Flow Mark Modeling");
174
                    foreach (var item in document.LINES)
175
                        FlowMarkModeling(item);
176
177 3939eebf gaqhf
                    // Note Modeling
178 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
179 3939eebf gaqhf
                    foreach (var item in document.NOTES)
180
                        NoteModeling(item);
181
182
                    // Text Modeling
183 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
184 3939eebf gaqhf
                    foreach (var item in document.TEXTINFOS)
185
                        TextModeling(item);
186
187
                    // LineRun Line Join
188 73415441 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
189 3939eebf gaqhf
                    foreach (LineNumber lineNumber in document.LINENUMBERS)
190
                        foreach (LineRun run in lineNumber.RUNS)
191
                            JoinRunLine(run);
192
                    // TrimLineRun Line Join
193
                    foreach (TrimLine trimLine in document.TRIMLINES)
194
                        foreach (LineRun run in trimLine.RUNS)
195
                            JoinRunLine(run);
196
197
                    // Input LineNumber Attribute
198 3ac248e3 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
199 3939eebf gaqhf
                    foreach (var item in document.LINENUMBERS)
200
                        InputLineNumberAttribute(item);
201
202
                    // Input Symbol Attribute
203 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
204 3939eebf gaqhf
                    foreach (var item in document.SYMBOLS)
205 73415441 gaqhf
                        InputSymbolAttribute(item, item.ATTRIBUTES);
206 3939eebf gaqhf
207 16584d30 gaqhf
                    // Input SpecBreak Attribute
208
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
209
                    foreach (var item in document.SpecBreaks)
210
                        InputSpecBreakAttribute(item);
211
212
                    // Label Symbol Modeling
213 f31645b6 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
214 3939eebf gaqhf
                    foreach (var item in document.SYMBOLS)
215 73415441 gaqhf
                        LabelSymbolModeling(item);
216 f31645b6 gaqhf
217
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount);
218 310aeb31 gaqhf
                }
219 809a7640 gaqhf
            }
220 5e6ecf05 gaqhf
            catch (Exception ex)
221
            {
222
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
223
            }
224
            finally
225
            {
226 1ba9c671 gaqhf
                application.ActiveWindow.Fit();
227 b2d1c1aa gaqhf
228 b66a2996 gaqhf
                if (radApp.ActiveDocument != null)
229 3939eebf gaqhf
                {
230 b66a2996 gaqhf
                    //radApp.ActiveDocument.Save();
231
                    //radApp.ActiveDocument.SaveOnClose = false;
232
                    //radApp.ActiveDocument.Close(false);
233
234 1ba9c671 gaqhf
                    ReleaseCOMObjects(newDrawing);
235 3939eebf gaqhf
                }
236 1ba9c671 gaqhf
237 5e6ecf05 gaqhf
                ReleaseCOMObjects(dataSource);
238
                ReleaseCOMObjects(_placement);
239 965eb728 gaqhf
240 b2d1c1aa gaqhf
                //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
241 965eb728 gaqhf
                SplashScreenManager.CloseForm(false);
242 5e6ecf05 gaqhf
            }
243 65a1ed4b gaqhf
        }
244
245 74752074 gaqhf
        /// <summary>
246
        /// 도면 생성 메서드
247
        /// </summary>
248 0e0edfad gaqhf
        private void CreateDocument()
249
        {
250 b66a2996 gaqhf
            string drawingName = document.DrawingName;
251
            string drawingNumber = document.DrawingNumber;
252
253
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
254
255
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
256 0e0edfad gaqhf
            application.ActiveWindow.Fit();
257
            Thread.Sleep(1000);
258
            application.ActiveWindow.Zoom = 2000;
259
            Thread.Sleep(2000);
260 b66a2996 gaqhf
261 e8536f2b gaqhf
            Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName);
262 b66a2996 gaqhf
        }
263
264 02480ac1 gaqhf
        /// <summary>
265
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
266
        /// </summary>
267
        /// <param name="drawingName"></param>
268
        /// <param name="drawingNumber"></param>
269 b66a2996 gaqhf
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
270
        {
271
            LMDrawings drawings = new LMDrawings();
272
            drawings.Collect(dataSource);
273
274
            List<string> drawingNameList = new List<string>();
275
            List<string> drawingNumberList = new List<string>();
276
277
            foreach (LMDrawing item in drawings)
278
            {
279
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
280
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
281
            }
282
283
            int nameLength = drawingName.Length;
284
            while (drawingNameList.Contains(drawingName))
285
            {
286
                if (nameLength == drawingName.Length)
287
                    drawingName += "-1";
288
                else
289
                {
290
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
291
                    drawingName = drawingName.Substring(0, nameLength + 1);
292
                    drawingName += ++index;
293
                }
294
            }
295
296
            int numberLength = drawingNumber.Length;
297
            while (drawingNameList.Contains(drawingNumber))
298
            {
299
                if (numberLength == drawingNumber.Length)
300
                    drawingNumber += "-1";
301
                else
302
                {
303
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
304
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
305
                    drawingNumber += ++index;
306
                }
307
            }
308
309
            ReleaseCOMObjects(drawings);
310 0e0edfad gaqhf
        }
311
312 74752074 gaqhf
        /// <summary>
313
        /// 도면 크기 구하는 메서드
314
        /// </summary>
315
        /// <returns></returns>
316 0e0edfad gaqhf
        private bool DocumentCoordinateCorrection()
317
        {
318 6a7573b0 gaqhf
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
319 0e0edfad gaqhf
            {
320 6a7573b0 gaqhf
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
321 c01ce90b gaqhf
                document.CoordinateCorrection();
322 0e0edfad gaqhf
                return true;
323
            }
324
            else
325
                return false;
326
        }
327
328 74752074 gaqhf
        /// <summary>
329
        /// 라인을 Run 단위로 모델링하는 진입 메서드
330
        /// </summary>
331
        /// <param name="run"></param>
332 8aa6f2db gaqhf
        private void LineModelingByRun(LineRun run)
333 809a7640 gaqhf
        {
334
            Line prevLine = null;
335
            List<Line> lines = new List<Line>();
336
            foreach (var item in run.RUNITEMS)
337
            {
338
                // Line일 경우
339
                if (item.GetType() == typeof(Line))
340
                {
341
                    Line line = item as Line;
342
                    if (prevLine == null)
343
                        lines.Add(line);
344
                    else if (prevLine != null)
345
                    {
346
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
347
                            lines.Add(line);
348
                        else
349 f1c9dbaa gaqhf
                        {
350 f2baa6a3 gaqhf
                            if (lines.Count > 0)
351
                            {
352
                                LineModeling(lines);
353
                                lines.Clear();
354
                            }
355 809a7640 gaqhf
                            lines.Add(line);
356 5dfb8a24 gaqhf
                        }
357
                    }
358
359 809a7640 gaqhf
                    prevLine = line;
360 f31645b6 gaqhf
361
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
362 809a7640 gaqhf
                }
363
                // Symbol 일 경우
364
                else if (item.GetType() == typeof(Symbol))
365
                {
366 f1c9dbaa gaqhf
                    if (lines.Count > 0)
367 809a7640 gaqhf
                    {
368 f1c9dbaa gaqhf
                        LineModeling(lines);
369 809a7640 gaqhf
                        lines.Clear();
370
                    }
371 5dfb8a24 gaqhf
                }
372
            }
373
374 809a7640 gaqhf
            if (lines.Count > 0)
375
                LineModeling(lines);
376
        }
377 5dfb8a24 gaqhf
378 74752074 gaqhf
        /// <summary>
379
        /// 심볼을 Run 단위로 모델링하는 진입 메서드
380
        /// </summary>
381
        /// <param name="run"></param>
382 8aa6f2db gaqhf
        private void SymbolModelingByRun(LineRun run)
383 809a7640 gaqhf
        {
384
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
385
            if (run.RUNITEMS.Count > 0)
386
            {
387
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
388
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
389
390
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
391
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
392
            }
393
394
            Symbol targetSymbol = null;
395
            foreach (var item in run.RUNITEMS)
396
            {
397
                if (item.GetType() == typeof(Symbol))
398
                {
399
                    Symbol symbol = item as Symbol;
400 b2d1c1aa gaqhf
                    SymbolModeling(symbol, targetSymbol);
401 809a7640 gaqhf
                    targetSymbol = symbol;
402
                }
403
                else
404
                {
405
                    targetSymbol = null;
406
                }
407
            }
408
        }
409
410 74752074 gaqhf
        /// <summary>
411
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점
412
        /// </summary>
413
        /// <param name="symbol"></param>
414
        /// <param name="run"></param>
415 8aa6f2db gaqhf
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
416 809a7640 gaqhf
        {
417
            foreach (var connector in symbol.CONNECTORS)
418
            {
419
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
420
                if (targetItem != null &&
421
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
422 74752074 gaqhf
                    !IsSameLineRun(symbol, targetItem))
423 809a7640 gaqhf
                {
424 b2d1c1aa gaqhf
                    SymbolModeling(symbol, targetItem as Symbol);
425 809a7640 gaqhf
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
426
                    {
427
                        object item = run.RUNITEMS[i];
428
                        if (item.GetType() == typeof(Symbol))
429 b2d1c1aa gaqhf
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol);
430 809a7640 gaqhf
                        else
431
                            break;
432
                    }
433
                    break;
434
                }
435
            }
436
437
438
        }
439
440 74752074 gaqhf
        /// <summary>
441
        /// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점
442
        /// </summary>
443
        /// <param name="symbol"></param>
444
        /// <param name="run"></param>
445 8aa6f2db gaqhf
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
446 809a7640 gaqhf
        {
447
            foreach (var connector in symbol.CONNECTORS)
448
            {
449
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
450
                if (targetItem != null &&
451
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
452 74752074 gaqhf
                    !IsSameLineRun(symbol, targetItem))
453 809a7640 gaqhf
                {
454 b2d1c1aa gaqhf
                    SymbolModeling(symbol, targetItem as Symbol);
455 809a7640 gaqhf
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
456
                    {
457
                        object item = run.RUNITEMS[i];
458
                        if (item.GetType() == typeof(Symbol))
459 b2d1c1aa gaqhf
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol);
460 809a7640 gaqhf
                        else
461
                            break;
462
                    }
463
                    break;
464
                }
465
            }
466 5dfb8a24 gaqhf
        }
467 cfda1fed gaqhf
468 74752074 gaqhf
        /// <summary>
469
        /// 심볼을 실제로 Modeling 메서드
470
        /// </summary>
471
        /// <param name="symbol"></param>
472
        /// <param name="targetSymbol"></param>
473
        /// <param name="prevSymbol"></param>
474 b2d1c1aa gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
475 809a7640 gaqhf
        {
476 4d2571ab gaqhf
#if DEBUG
477
            try
478
            {
479
#endif
480 6a7573b0 gaqhf
                // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
481
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
482
                if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None")
483
                    return;
484
                // 이미 모델링 됐을 경우
485
                else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
486
                    return;
487
488
                LMSymbol _LMSymbol = null;
489
490
                string mappingPath = symbol.SPPID.MAPPINGNAME;
491
                double x = symbol.SPPID.ORIGINAL_X;
492
                double y = symbol.SPPID.ORIGINAL_Y;
493
                int mirror = 0;
494
                double angle = symbol.ANGLE;
495
496
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
497
498
                // OPC 일경우 180도 일때 Mirror
499
                if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
500
                    mirror = 1;
501
502
                // Mirror 계산
503
                if (symbol.FLIP == 1)
504
                {
505
                    mirror = 1;
506
                    angle += Math.PI;
507
                }
508 809a7640 gaqhf
509 6a7573b0 gaqhf
                if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
510
                {
511
                    LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
512
                    Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
513
                    if (connector != null)
514
                        GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
515 2fdb56bf gaqhf
516 6a7573b0 gaqhf
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
517 1ab9a205 gaqhf
518
                    if (_LMSymbol != null && _TargetItem != null)
519
                    {
520
                        symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
521
                        LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
522
523
                        if (reModelingConnector != null)
524
                            ReModelingLMConnector(reModelingConnector);
525
                    }
526
527 6a7573b0 gaqhf
                    ReleaseCOMObjects(_TargetItem);
528
                }
529
                else
530
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
531 809a7640 gaqhf
532
533 6a7573b0 gaqhf
                if (_LMSymbol != null)
534
                {
535
                    _LMSymbol.Commit();
536
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
537
                    symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
538 ac78b508 gaqhf
539 6a7573b0 gaqhf
                    foreach (var item in symbol.ChildSymbols)
540
                        CreateChildSymbol(item, _LMSymbol);
541
                }
542 809a7640 gaqhf
543 6a7573b0 gaqhf
                ReleaseCOMObjects(_LMSymbol);
544
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
545 4d2571ab gaqhf
#if DEBUG
546
547
            }
548
            catch (Exception ex)
549
            {
550
                System.Windows.Forms.MessageBox.Show(ex.StackTrace);
551
            }
552
#endif
553 809a7640 gaqhf
        }
554
555 d1eac84d gaqhf
        /// <summary>
556
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
557
        /// </summary>
558
        /// <param name="targetConnector"></param>
559
        /// <param name="targetSymbol"></param>
560
        /// <param name="x"></param>
561
        /// <param name="y"></param>
562
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
563
        {
564
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
565 2fdb56bf gaqhf
566
            double[] range = null;
567 d1eac84d gaqhf
            List<double[]> points = new List<double[]>();
568 2fdb56bf gaqhf
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
569
            double x1 = range[0];
570
            double y1 = range[1];
571
            double x2 = range[2];
572
            double y2 = range[3];
573 d1eac84d gaqhf
574
            // Origin 기준 Connector의 위치차이
575
            double sceneX = 0;
576
            double sceneY = 0;
577
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
578
            double originX = 0;
579
            double originY = 0;
580
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
581
            double gapX = originX - sceneX;
582
            double gapY = originY - sceneY;
583
584
            // SPPID Symbol과 ID2 심볼의 크기 차이
585
            double sizeWidth = 0;
586
            double sizeHeight = 0;
587
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
588
            double percentX = (x2 - x1) / sizeWidth;
589
            double percentY = (y2 - y1) / sizeHeight;
590
591
            double SPPIDgapX = gapX * percentX;
592
            double SPPIDgapY = gapY * percentY;
593
594
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
595
            double distance = double.MaxValue;
596
            double[] resultPoint;
597
            foreach (var point in points)
598
            {
599
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
600
                if (distance > result)
601
                {
602
                    distance = result;
603
                    resultPoint = point;
604
                    x = point[0];
605
                    y = point[1];
606
                }
607
            }
608 2fdb56bf gaqhf
609
            ReleaseCOMObjects(_TargetItem);
610
        }
611
612
        /// <summary>
613
        /// SPPID Symbol의 Range를 구한다.
614
        /// </summary>
615
        /// <param name="symbol"></param>
616
        /// <param name="range"></param>
617
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
618
        {
619
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
620
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
621
            double x1 = 0;
622
            double y1 = 0;
623
            double x2 = 0;
624
            double y2 = 0;
625
            symbol2d.Range(out x1, out y1, out x2, out y2);
626
            range = new double[] { x1, y1, x2, y2 };
627
628
            for (int i = 1; i < int.MaxValue; i++)
629
            {
630
                double connX = 0;
631
                double connY = 0;
632
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
633
                    points.Add(new double[] { connX, connY });
634
                else
635
                    break;
636
            }
637
638
            foreach (var childSymbol in symbol.ChildSymbols)
639
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
640
641
            ReleaseCOMObjects(_TargetItem);
642
        }
643
644
        /// <summary>
645
        /// Child Modeling 된 Symbol의 Range를 구한다.
646
        /// </summary>
647
        /// <param name="childSymbol"></param>
648
        /// <param name="range"></param>
649
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
650
        {
651
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
652
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
653
            double x1 = 0;
654
            double y1 = 0;
655
            double x2 = 0;
656
            double y2 = 0;
657
            symbol2d.Range(out x1, out y1, out x2, out y2);
658
            range[0] = Math.Min(range[0], x1);
659
            range[1] = Math.Min(range[1], y1);
660
            range[2] = Math.Max(range[2], x2);
661
            range[3] = Math.Max(range[3], y2);
662
663
            for (int i = 1; i < int.MaxValue; i++)
664
            {
665
                double connX = 0;
666
                double connY = 0;
667
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
668
                    points.Add(new double[] { connX, connY });
669
                else
670
                    break;
671
            }
672
673
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
674
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
675
676
            ReleaseCOMObjects(_ChildSymbol);
677 d1eac84d gaqhf
        }
678
679
        /// <summary>
680
        /// Label Symbol Modeling
681
        /// </summary>
682
        /// <param name="symbol"></param>
683 73415441 gaqhf
        private void LabelSymbolModeling(Symbol symbol)
684
        {
685
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
686
            if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE))
687
                return;
688
689
            Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
690
            
691
            string symbolUID = itemAttribute.VALUE;
692
            object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
693
            if (targetItem != null)
694
            {
695
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
696
                string sRep = null;
697
                if (targetItem.GetType() == typeof(Symbol))
698
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
699
                else if (targetItem.GetType() == typeof(Equipment))
700
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
701
702
                if (!string.IsNullOrEmpty(sRep))
703
                {
704
                    // LEADER Line 검사
705
                    bool leaderLine = false;
706
                    SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
707
                    if (symbolMapping != null)
708
                        leaderLine = symbolMapping.LEADERLINE;
709
710
                    // Target Symbol Item 가져오고 Label Modeling
711
                    LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
712
                    LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
713
714
                    //Leader 선 센터로
715 b2d1c1aa gaqhf
                    if (_LMLabelPresist != null)
716 73415441 gaqhf
                    {
717 b2d1c1aa gaqhf
                        // Target Item에 Label의 Attribute Input
718
                        InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
719
720
                        string OID = _LMLabelPresist.get_GraphicOID();
721
                        DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
722
                        if (dependency != null)
723 73415441 gaqhf
                        {
724 b2d1c1aa gaqhf
                            bool result = false;
725
                            foreach (var attributes in dependency.AttributeSets)
726 73415441 gaqhf
                            {
727 b2d1c1aa gaqhf
                                foreach (var attribute in attributes)
728 73415441 gaqhf
                                {
729 b2d1c1aa gaqhf
                                    string name = attribute.Name;
730
                                    string value = attribute.GetValue().ToString();
731
                                    if (name == "DrawingItemType" && value == "LabelPersist")
732 73415441 gaqhf
                                    {
733 b2d1c1aa gaqhf
                                        foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
734 73415441 gaqhf
                                        {
735 b2d1c1aa gaqhf
                                            if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
736
                                            {
737
                                                Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
738
                                                double prevX = _TargetItem.get_XCoordinate();
739
                                                double prevY = _TargetItem.get_YCoordinate();
740
                                                lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
741
                                                lineString2D.RemoveVertex(lineString2D.VertexCount);
742
                                                result = true;
743
                                                break;
744
                                            }
745 73415441 gaqhf
                                        }
746
                                    }
747 b2d1c1aa gaqhf
748
                                    if (result)
749
                                        break;
750 73415441 gaqhf
                                }
751
752
                                if (result)
753
                                    break;
754
                            }
755
                        }
756
757 b2d1c1aa gaqhf
                        _LMLabelPresist.Commit();
758
                    }
759
                    
760 73415441 gaqhf
                    ReleaseCOMObjects(_TargetItem);
761
                    ReleaseCOMObjects(_LMLabelPresist);
762
                }
763
            }
764
765
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
766
        }
767
768 74752074 gaqhf
        /// <summary>
769
        /// Equipment를 실제로 Modeling 메서드
770
        /// </summary>
771
        /// <param name="equipment"></param>
772 b9e9f4c8 gaqhf
        private void EquipmentModeling(Equipment equipment)
773
        {
774
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
775
                return;
776
777
            LMSymbol _LMSymbol = null;
778
            LMSymbol targetItem = null;
779
            string mappingPath = equipment.SPPID.MAPPINGNAME;
780
            double x = equipment.SPPID.ORIGINAL_X;
781
            double y = equipment.SPPID.ORIGINAL_Y;
782
            int mirror = 0;
783
            double angle = equipment.ANGLE;
784
785 20972c61 gaqhf
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
786
787 b9e9f4c8 gaqhf
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
788
            if (connector != null)
789
            {
790
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
791
                if (connEquipment != null)
792
                {
793
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
794
                        EquipmentModeling(connEquipment);
795
796
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
797
                    {
798
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
799
                        if (targetItem != null)
800
                        {
801
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
802
                        }
803
                        else
804
                        {
805
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
806
                        }
807
                    }
808
                    else
809
                    {
810
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
811
                    }
812
                }
813
                else
814
                {
815
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
816
                }
817
            }
818
            else
819
            {
820
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
821
            }
822
823
            if (_LMSymbol != null)
824
            {
825
                _LMSymbol.Commit();
826
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
827 20972c61 gaqhf
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
828 b9e9f4c8 gaqhf
                ReleaseCOMObjects(_LMSymbol);
829
            }
830
831
            if (targetItem != null)
832
            {
833
                ReleaseCOMObjects(targetItem);
834
            }
835
            
836
            ReleaseCOMObjects(_LMSymbol);
837 f31645b6 gaqhf
838
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
839 b9e9f4c8 gaqhf
        }
840
841 4d2571ab gaqhf
        private void SymbolModelingByPriority(Symbol symbol)
842 d1eac84d gaqhf
        {
843 4d2571ab gaqhf
            // Angle, Center, 우선순위 모델링
844
            SymbolModeling(symbol, null);
845
            List<Symbol> group = new List<Symbol>() { symbol };
846
            SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group);
847 d1eac84d gaqhf
848 4d2571ab gaqhf
            List<Symbol> endModeling = new List<Symbol>() { symbol };
849
            while (endModeling.Count != group.Count)
850
            {
851
                foreach (var item in group)
852 d1eac84d gaqhf
                {
853 4d2571ab gaqhf
                    if (!endModeling.Contains(item))
854
                    {
855
                        bool result = false;
856
                        foreach (var connector in item.CONNECTORS)
857
                        {
858
                            Symbol connSymbol = group.Find(x => x.UID == connector.CONNECTEDITEM);
859
                            if (connSymbol == item)
860
                                throw new Exception(connSymbol.UID);
861
862
                            if (connSymbol != null && endModeling.Contains(connSymbol))
863
                            {
864
                                SymbolModeling(item, connSymbol);
865
                                endModeling.Add(item);
866
                                result = true;
867
                                break;
868
                            }
869
                        }
870
871
                        if (result)
872
                            break;
873
                    }
874 d1eac84d gaqhf
                }
875
            }
876
        }
877
878
        /// <summary>
879 74752074 gaqhf
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
880
        /// </summary>
881
        /// <param name="childSymbol"></param>
882
        /// <param name="parentSymbol"></param>
883 4b4dbca9 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
884 ac78b508 gaqhf
        {
885 4b4dbca9 gaqhf
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
886
            double x1 = 0;
887
            double x2 = 0;
888
            double y1 = 0;
889
            double y2 = 0;
890
            symbol2d.Range(out x1, out y1, out x2, out y2);
891
892
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
893
            if (_LMSymbol != null)
894
            {
895
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
896
                foreach (var item in childSymbol.ChildSymbols)
897
                    CreateChildSymbol(item, _LMSymbol);
898
            }
899
            
900 ac78b508 gaqhf
901
            ReleaseCOMObjects(_LMSymbol);
902
        }
903
904 74752074 gaqhf
        /// <summary>
905
        /// item이 TargetItem과 같은 LineRun에 있는지 검사
906
        /// </summary>
907
        /// <param name="item"></param>
908
        /// <param name="targetItem"></param>
909
        /// <returns></returns>
910
        private bool IsSameLineRun(object item, object targetItem)
911 809a7640 gaqhf
        {
912
            foreach (var lineNumber in document.LINENUMBERS)
913
            {
914
                foreach (var run in lineNumber.RUNS)
915
                {
916
                    foreach (var runItem in run.RUNITEMS)
917
                    {
918
                        if (runItem == item)
919
                        {
920
                            foreach (var findItem in run.RUNITEMS)
921
                            {
922
                                if (findItem == targetItem)
923
                                {
924
                                    return true;
925
                                }
926
                            }
927
928
                            return false;
929
930
                        }
931
                    }
932
                }
933
            }
934
935
            return false;
936
        }
937
938 74752074 gaqhf
        /// <summary>
939
        /// Line을 실제로 모델링하는 메서드
940
        /// </summary>
941
        /// <param name="lines"></param>
942 1b261371 gaqhf
        private void LineModeling(List<Line> lines)
943
        {
944 335b7a24 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
945 1b261371 gaqhf
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
946 f1c9dbaa gaqhf
            LMSymbol _LMSymbol1 = null;
947
            LMSymbol _LMSymbol2 = null;
948 5e6ecf05 gaqhf
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
949
            LMConnector targetConnector1 = null;
950
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
951
            LMConnector targetConnector2 = null;
952 1ab9a205 gaqhf
            
953 335b7a24 gaqhf
            Line startBranchLine = null;
954
            Line endBranchLine = null;
955
956 0bbd73b5 gaqhf
            // Type, Line, TargetObjet, x, y
957
            List<Tuple<string, Line, object, double, double>> linePointInfo = new List<Tuple<string, Line, object, double, double>>();
958
            // Point 정리
959 1b261371 gaqhf
            for (int i = 0; i < lines.Count; i++)
960
            {
961
                Line line = lines[i];
962 f1c9dbaa gaqhf
                if (i == 0 || i + 1 != lines.Count)
963
                {
964 809a7640 gaqhf
                    // 시작점에 연결된 Symbol 찾기
965 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
966
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
967
                    {
968 2fdb56bf gaqhf
                        Symbol symbol1 = connItem as Symbol;
969
                        _LMSymbol1 = GetTargetSymbol(symbol1, line);
970 f1c9dbaa gaqhf
                        if (_LMSymbol1 != null)
971 2fdb56bf gaqhf
                        {
972
                            double x = line.SPPID.START_X;
973
                            double y = line.SPPID.START_Y;
974
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1);
975
                            if (connector != null)
976
                            {
977
                                GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y);
978
                                line.SPPID.START_X = x;
979
                                line.SPPID.START_Y = y;
980
                            }
981
982 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol1, x, y));
983 2fdb56bf gaqhf
                        }
984 f1c9dbaa gaqhf
                        else
985 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
986 f1c9dbaa gaqhf
                    }
987 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
988 5e6ecf05 gaqhf
                    {
989
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
990 56bc67e1 gaqhf
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
991 5e6ecf05 gaqhf
992
                        if (targetConnector1 != null)
993 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector1, line.SPPID.START_X, line.SPPID.START_Y));
994 5e6ecf05 gaqhf
                        else
995 335b7a24 gaqhf
                        {
996
                            startBranchLine = connItem as Line;
997 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
998 335b7a24 gaqhf
                        }
999 5e6ecf05 gaqhf
                    }
1000 f1c9dbaa gaqhf
                    else
1001 0bbd73b5 gaqhf
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1002 ca7d0ada gaqhf
                        
1003 f1c9dbaa gaqhf
                }
1004
                if (i + 1 == lines.Count)
1005
                {
1006 809a7640 gaqhf
                    // 끝점에 연결된 Symbol 찾기
1007 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
1008 5e6ecf05 gaqhf
1009
                    if (i != 0)
1010 0bbd73b5 gaqhf
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y));
1011 5e6ecf05 gaqhf
1012 f1c9dbaa gaqhf
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
1013
                    {
1014 2fdb56bf gaqhf
                        Symbol symbol2 = connItem as Symbol;
1015 f2baa6a3 gaqhf
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
1016 f1c9dbaa gaqhf
                        if (_LMSymbol2 != null)
1017 2fdb56bf gaqhf
                        {
1018
                            double x = line.SPPID.END_X;
1019
                            double y = line.SPPID.END_Y;
1020
                            Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2);
1021
                            if (connector != null)
1022
                            {
1023
                                GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y);
1024
                                line.SPPID.END_X = x;
1025
                                line.SPPID.END_Y = y;
1026
                            }
1027
1028 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol2, x, y));
1029 2fdb56bf gaqhf
                        }
1030 f1c9dbaa gaqhf
                        else
1031 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1032 f1c9dbaa gaqhf
                    }
1033 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
1034 5e6ecf05 gaqhf
                    {
1035
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
1036 56bc67e1 gaqhf
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
1037 5e6ecf05 gaqhf
1038
                        if (targetConnector2 != null)
1039 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector2, line.SPPID.END_X, line.SPPID.END_Y));
1040 5e6ecf05 gaqhf
                        else
1041 335b7a24 gaqhf
                        {
1042
                            endBranchLine = connItem as Line;
1043 0bbd73b5 gaqhf
                            linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1044 335b7a24 gaqhf
                        }
1045 5e6ecf05 gaqhf
                    }
1046 f1c9dbaa gaqhf
                    else
1047 0bbd73b5 gaqhf
                        linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y));
1048 f1c9dbaa gaqhf
                }
1049
            }
1050
1051 0bbd73b5 gaqhf
            double prevX = double.NaN;
1052
            double prevY = double.NaN;
1053
            SlopeType prevSlopeType = SlopeType.None;
1054 ca7d0ada gaqhf
            for (int i = 0; i < linePointInfo.Count; i++)
1055
            {
1056 0bbd73b5 gaqhf
                Tuple<string, Line, object, double, double> item = linePointInfo[i];
1057
                Line line = item.Item2;
1058
                double x = item.Item4;
1059
                double y = item.Item5;
1060
                SlopeType slopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
1061
                // Symbol일 경우 바로 Input Point
1062 ca7d0ada gaqhf
                if (item.Item1 == "SYMBOL")
1063 0bbd73b5 gaqhf
                    placeRunInputs.AddSymbolTarget(item.Item3 as LMSymbol, x, y);
1064 b66a2996 gaqhf
                else
1065 0bbd73b5 gaqhf
                {
1066 b66a2996 gaqhf
                    SPPIDUtil.ConvertGridPoint(ref x, ref y);
1067
                    // i == 0은 그대로 사용
1068
                    if (i != 0)
1069 0bbd73b5 gaqhf
                    {
1070 b66a2996 gaqhf
                        Tuple<string, Line, object, double, double> prevItem = linePointInfo[i - 1];
1071
                        // y 좌표가 같아야함 및 Symbol 좌표가 정확하지 않으므로 한번더 보정
1072
                        if (prevSlopeType == SlopeType.HORIZONTAL)
1073
                        {
1074
                            y = prevY;
1075
                            SPPIDUtil.ConvertGridPointOnlyOnePoint(ref y);
1076
                        }
1077
                        else if (prevSlopeType == SlopeType.VERTICAL)
1078
                        {
1079
                            x = prevX;
1080
                            SPPIDUtil.ConvertGridPointOnlyOnePoint(ref x);
1081
                        }
1082
1083
                        // 마지막이 Symbol일 경우는 Symbol의 좌표를 따라감
1084
                        if (i + 1 == linePointInfo.Count - 1 && linePointInfo[i + 1].Item1 == "SYMBOL")
1085
                        {
1086
                            Line nextLine = linePointInfo[i + 1].Item2;
1087
                            SlopeType nextSlopeType = SPPIDUtil.CalcSlope(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y);
1088
                            if (slopeType == SlopeType.HORIZONTAL)
1089
                                y = linePointInfo[i + 1].Item5;
1090
                            else if (slopeType == SlopeType.VERTICAL)
1091
                                x = linePointInfo[i + 1].Item4;
1092
                        }
1093 0bbd73b5 gaqhf
                    }
1094
1095 b66a2996 gaqhf
                    if (item.Item1 == "LINE")
1096
                        placeRunInputs.AddConnectorTarget(item.Item3 as LMConnector, x, y);
1097
                    else
1098
                        placeRunInputs.AddPoint(x, y);
1099
                }
1100 0bbd73b5 gaqhf
1101
                prevX = x;
1102
                prevY = y;
1103
                prevSlopeType = slopeType;
1104 ca7d0ada gaqhf
            }
1105
1106 f1c9dbaa gaqhf
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1107 335b7a24 gaqhf
1108 f1c9dbaa gaqhf
            if (_lMConnector != null)
1109
            {
1110 1ab9a205 gaqhf
                if (_LMSymbol1 != null || _LMSymbol2 != null)
1111
                    ReModelingLine(lines, _lMConnector, _LMSymbol1, _LMSymbol2);
1112
                else
1113
                {
1114
                    foreach (var line in lines)
1115
                        line.SPPID.ModelItemId = _lMConnector.ModelItemID;
1116
                    _lMConnector.Commit();
1117
                }
1118 335b7a24 gaqhf
                if (startBranchLine != null || endBranchLine != null)
1119 1ab9a205 gaqhf
                    BranchLines.Add(new Tuple<string, Line, Line>(lines[0].SPPID.ModelItemId, startBranchLine, endBranchLine));
1120
                
1121 1b261371 gaqhf
            }
1122 5e6ecf05 gaqhf
1123 f1c9dbaa gaqhf
            if (_LMSymbol1 != null)
1124
                ReleaseCOMObjects(_LMSymbol1);
1125
            if (_LMSymbol2 != null)
1126
                ReleaseCOMObjects(_LMSymbol2);
1127 5e6ecf05 gaqhf
            if (targetConnector1 != null)
1128
                ReleaseCOMObjects(targetConnector1);
1129
            if (targetConnector2 != null)
1130
                ReleaseCOMObjects(targetConnector2);
1131
            foreach (var item in connectorVertices1)
1132
                ReleaseCOMObjects(item.Key);
1133
            foreach (var item in connectorVertices2)
1134
                ReleaseCOMObjects(item.Key);
1135 1b261371 gaqhf
1136 f1c9dbaa gaqhf
            ReleaseCOMObjects(_lMConnector);
1137 1b261371 gaqhf
            ReleaseCOMObjects(placeRunInputs);
1138
            ReleaseCOMObjects(_LMAItem);
1139
        }
1140
1141 74752074 gaqhf
        /// <summary>
1142 1ab9a205 gaqhf
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1143
        /// </summary>
1144
        /// <param name="lines"></param>
1145
        /// <param name="prevLMConnector"></param>
1146
        /// <param name="startSymbol"></param>
1147
        /// <param name="endSymbol"></param>
1148
        private void ReModelingLine(List<Line> lines, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol)
1149
        {
1150
            
1151
            string symbolPath = string.Empty;
1152
            #region get symbol path
1153
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1154
            foreach (LMRepresentation rep in modelItem.Representations)
1155
            {
1156
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1157
                {
1158
                    symbolPath = rep.get_FileName();
1159
                    break;
1160
                }
1161
            }
1162
            #endregion
1163
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1164
            LMConnector newConnector = null;
1165
            dynamic OID = prevLMConnector.get_GraphicOID();
1166
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1167
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1168
            int verticesCount = lineStringGeometry.VertexCount;
1169
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1170
            
1171
            List<double[]> vertices = new List<double[]>();
1172
            for (int i = 1; i <= verticesCount; i++)
1173
            {
1174
                double x = 0;
1175
                double y = 0;
1176
                lineStringGeometry.GetVertex(i, ref x, ref y);
1177
                vertices.Add(new double[] { x, y });
1178
            }
1179
1180
            for (int i = 0; i < vertices.Count; i++)
1181
            {
1182
                double[] points = vertices[i];
1183
                // 시작 심볼이 있고 첫번째 좌표일 때
1184
                if (startSymbol != null && i == 0)
1185
                {
1186
                    SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1187
                    if (slopeType == SlopeType.HORIZONTAL)
1188
                        placeRunInputs.AddPoint(points[0], -0.1);
1189
                    else if (slopeType == SlopeType.VERTICAL)
1190
                        placeRunInputs.AddPoint(-0.1, points[1]);
1191
                    else
1192
                        placeRunInputs.AddPoint(points[0], -0.1);
1193
1194
                    placeRunInputs.AddPoint(points[0], points[1]);
1195
                }
1196
                // 마지막 심볼이 있고 마지막 좌표일 때
1197
                else if (endSymbol != null && i == vertices.Count - 1)
1198
                {
1199
                    placeRunInputs.AddPoint(points[0], points[1]);
1200
1201
                    SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1202
                    if (slopeType == SlopeType.HORIZONTAL)
1203
                        placeRunInputs.AddPoint(points[0], -0.1);
1204
                    else if (slopeType == SlopeType.VERTICAL)
1205
                        placeRunInputs.AddPoint(-0.1, points[1]);
1206
                    else
1207
                        placeRunInputs.AddPoint(points[0], -0.1);
1208
                }
1209
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1210
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1211
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1212
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1213
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1214
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1215
                else
1216
                    placeRunInputs.AddPoint(points[0], points[1]);
1217
            }
1218
1219
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1220
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1221
1222
            ReleaseCOMObjects(placeRunInputs);
1223
            ReleaseCOMObjects(_LMAItem);
1224
            ReleaseCOMObjects(modelItem);
1225
1226
            if (newConnector != null)
1227
            {
1228
                if (startSymbol != null)
1229
                {
1230
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1231
                    placeRunInputs = new PlaceRunInputs();
1232
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1233
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1234
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1235
                    if (_LMConnector != null)
1236
                    {
1237
                        RemoveConnectorForReModelingLine(newConnector);
1238
                        ReleaseCOMObjects(_LMConnector);
1239
                    }
1240
                    ReleaseCOMObjects(placeRunInputs);
1241
                    ReleaseCOMObjects(_LMAItem);
1242
                }
1243
1244
                if (endSymbol != null)
1245
                {
1246
                    if (startSymbol != null)
1247
                    {
1248
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1249
                        newConnector = dicVertices.First().Key;
1250
                    }
1251
1252
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1253
                    placeRunInputs = new PlaceRunInputs();
1254
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1255
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1256
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1257
                    if (_LMConnector != null)
1258
                    {
1259
                        RemoveConnectorForReModelingLine(newConnector);
1260
                        ReleaseCOMObjects(_LMConnector);
1261
                    }
1262
                    ReleaseCOMObjects(placeRunInputs);
1263
                    ReleaseCOMObjects(_LMAItem);
1264
                }
1265
1266
                foreach (var line in lines)
1267
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
1268
                ReleaseCOMObjects(newConnector);
1269
            }
1270
1271
            ReleaseCOMObjects(modelItem);
1272
        }
1273
1274
        /// <summary>
1275
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
1276
        /// </summary>
1277
        /// <param name="connector"></param>
1278
        private void RemoveConnectorForReModelingLine(LMConnector connector)
1279
        {
1280
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
1281
            foreach (var item in dicVertices)
1282
            {
1283
                bool result = false;
1284
                foreach (var point in item.Value)
1285
                {
1286
                    if (point[0] < 0 || point[1] < 0)
1287
                    {
1288
                        result = true;
1289
                        _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
1290
                        break;
1291
                    }
1292
                }
1293
1294
                if (result)
1295
                    break;
1296
            }
1297
            foreach (var item in dicVertices)
1298
                ReleaseCOMObjects(item.Key);
1299
        }
1300
1301
        /// <summary>
1302 74752074 gaqhf
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
1303
        /// </summary>
1304
        /// <param name="symbol"></param>
1305
        /// <param name="line"></param>
1306
        /// <returns></returns>
1307 f2baa6a3 gaqhf
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
1308
        {
1309
            LMSymbol _LMSymbol = null;
1310
            foreach (var connector in symbol.CONNECTORS)
1311
            {
1312
                if (connector.CONNECTEDITEM == line.UID)
1313
                {
1314
                    if (connector.Index == 0)
1315
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1316
                    else
1317
                    {
1318
                        ChildSymbol child = null;
1319
                        foreach (var childSymbol in symbol.ChildSymbols)
1320
                        {
1321
                            if (childSymbol.Connectors.Contains(connector))
1322
                                child = childSymbol;
1323
                            else
1324
                                child = GetChildSymbolByConnector(childSymbol, connector);
1325
1326
                            if (child != null)
1327
                                break;
1328
                        }
1329
1330
                        if (child != null)
1331
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
1332
                    }
1333
1334
                    break;  
1335
                }
1336
            }
1337
1338
            return _LMSymbol;
1339
        }
1340
1341 74752074 gaqhf
        /// <summary>
1342
        /// Connector를 가지고 있는 ChildSymbol Object 반환
1343
        /// </summary>
1344
        /// <param name="item"></param>
1345
        /// <param name="connector"></param>
1346
        /// <returns></returns>
1347 f2baa6a3 gaqhf
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
1348
        {
1349
            foreach (var childSymbol in item.ChildSymbols)
1350
            {
1351
                if (childSymbol.Connectors.Contains(connector))
1352
                    return childSymbol;
1353
                else
1354
                    return GetChildSymbolByConnector(childSymbol, connector);
1355
            }
1356
1357
            return null;
1358
        }
1359
1360 74752074 gaqhf
        /// <summary>
1361
        /// Branch 라인을 다시 모델링하는 진입 메서드
1362
        /// </summary>
1363
        /// <param name="branch"></param>
1364 335b7a24 gaqhf
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
1365
        {
1366
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1367 b66a2996 gaqhf
1368 335b7a24 gaqhf
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1369
1370 8b085570 gaqhf
            LMConnector _StartConnector = null;
1371
            LMConnector _EndConnector = null;
1372 335b7a24 gaqhf
            double lengthStart = double.MaxValue;
1373
            double lengthEnd = double.MaxValue;
1374
            List<double[]> startPoints = new List<double[]>();
1375
            List<double[]> endPoints = new List<double[]>();
1376
1377
            foreach (var item in connectorVertices)
1378
            {
1379
                foreach (var point in item.Value)
1380
                {
1381
                    // Start Point가 Branch
1382
                    if (branch.Item2 != null)
1383
                    {
1384
                        Line targetLine = branch.Item2;
1385
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1386
                        if (lengthStart > distance)
1387
                        {
1388 8b085570 gaqhf
                            _StartConnector = item.Key;
1389 335b7a24 gaqhf
                            lengthStart = distance;
1390
                            startPoints = item.Value;
1391
                        }
1392
                    }
1393
                    // End Point가 Branch
1394
                    if (branch.Item3 != null)
1395
                    {
1396
                        Line targetLine = branch.Item3;
1397
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
1398
                        if (lengthEnd > distance)
1399
                        {
1400 8b085570 gaqhf
                            _EndConnector = item.Key;
1401 335b7a24 gaqhf
                            lengthEnd = distance;
1402
                            endPoints = item.Value;
1403
                        }
1404
                    }
1405
                }
1406
            }
1407
            #region Branch가 양쪽 전부일 때
1408 8b085570 gaqhf
            if (_StartConnector != null && _StartConnector == _EndConnector)
1409 335b7a24 gaqhf
            {
1410 8b085570 gaqhf
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
1411 335b7a24 gaqhf
1412
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1413
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1414
1415
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1416 8b085570 gaqhf
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
1417 335b7a24 gaqhf
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1418 8b085570 gaqhf
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
1419 335b7a24 gaqhf
                   startPoints[startPoints.Count - 1][0],
1420
                   startPoints[startPoints.Count - 1][1],
1421
                   startPoints[startPoints.Count - 2][0],
1422
                   startPoints[startPoints.Count - 2][1]);
1423
1424
                for (int i = 0; i < startPoints.Count; i++)
1425
                {
1426
                    double[] point = startPoints[i];
1427
                    if (i == 0)
1428 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
1429 335b7a24 gaqhf
                    else if (i == startPoints.Count - 1)
1430 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
1431 335b7a24 gaqhf
                    else
1432
                        placeRunInputs.AddPoint(point[0], point[1]);
1433
                }
1434
1435
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1436
                if (_LMConnector != null)
1437
                {
1438
                    _LMConnector.Commit();
1439
                    foreach (var item in lines)
1440
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1441
                }
1442
1443
                foreach (var item in startConnectorVertices)
1444
                    ReleaseCOMObjects(item.Key);
1445
                foreach (var item in endConnectorVertices)
1446
                    ReleaseCOMObjects(item.Key);
1447
                ReleaseCOMObjects(placeRunInputs);
1448
                ReleaseCOMObjects(_LMAItem);
1449
                ReleaseCOMObjects(_LMConnector);
1450
            }
1451
            #endregion
1452 8b085570 gaqhf
            #region 양쪽이 다른 Branch 
1453 335b7a24 gaqhf
            else
1454
            {
1455
                // Branch 시작 Connector
1456 8b085570 gaqhf
                if (_StartConnector != null)
1457 6b298450 gaqhf
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
1458 335b7a24 gaqhf
1459 6b298450 gaqhf
                // Branch 끝 Connector
1460
                if (_EndConnector != null)
1461
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
1462
            }
1463
            #endregion
1464 335b7a24 gaqhf
1465 6b298450 gaqhf
            if (_StartConnector != null)
1466
                ReleaseCOMObjects(_StartConnector);
1467
            if (_EndConnector != null)
1468
                ReleaseCOMObjects(_EndConnector);
1469
            foreach (var item in connectorVertices)
1470
                ReleaseCOMObjects(item.Key);
1471
        }
1472 335b7a24 gaqhf
1473 74752074 gaqhf
        /// <summary>
1474
        /// Branch 라인을 다시 실제로 모델링하는 메서드
1475
        /// </summary>
1476
        /// <param name="branch"></param>
1477
        /// <param name="_Connector"></param>
1478
        /// <param name="points"></param>
1479
        /// <param name="IsStart"></param>
1480 6b298450 gaqhf
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
1481
        {
1482
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
1483
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
1484
            LMConnector _SameRunTargetConnector = null;
1485
            LMSymbol _SameRunTargetSymbol = null;
1486
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
1487
            LMConnector _BranchTargetConnector = null;
1488
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1489 335b7a24 gaqhf
1490 6b298450 gaqhf
            // 같은 Line Run의 Connector 찾기
1491
            foreach (var item in connectorVertices)
1492
            {
1493
                if (item.Key == _Connector)
1494
                    continue;
1495 335b7a24 gaqhf
1496 6b298450 gaqhf
                if (IsStart &&
1497
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
1498
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
1499
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
1500
                {
1501
                    _SameRunTargetConnector = item.Key;
1502
                    break;
1503
                }
1504
                else if (!IsStart &&
1505
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
1506
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
1507
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
1508
                {
1509
                    _SameRunTargetConnector = item.Key;
1510
                    break;
1511
                }
1512
            }
1513
1514
            // Branch 반대편이 Symbol
1515
            if (_SameRunTargetConnector == null)
1516
            {
1517
                foreach (var line in lines)
1518
                {
1519
                    foreach (var connector in line.CONNECTORS)
1520 335b7a24 gaqhf
                    {
1521 6b298450 gaqhf
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
1522
                        if (symbol != null)
1523 335b7a24 gaqhf
                        {
1524 6b298450 gaqhf
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1525
                            break;
1526 335b7a24 gaqhf
                        }
1527
                    }
1528 6b298450 gaqhf
                }
1529
            }
1530 335b7a24 gaqhf
1531 6b298450 gaqhf
            // 기존 Connector 제거
1532
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
1533
            
1534
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
1535
            if (IsStart)
1536
            {
1537
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
1538
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
1539
            }
1540
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
1541
            else
1542
            {
1543
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
1544
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
1545
                    points[points.Count - 1][0],
1546
                    points[points.Count - 1][1],
1547
                    points[points.Count - 2][0],
1548
                    points[points.Count - 2][1]);
1549
            }
1550 335b7a24 gaqhf
1551 6b298450 gaqhf
            for (int i = 0; i < points.Count; i++)
1552
            {
1553
                double[] point = points[i];
1554
                if (i == 0)
1555 335b7a24 gaqhf
                {
1556 6b298450 gaqhf
                    if (IsStart)
1557 335b7a24 gaqhf
                    {
1558 b2d1c1aa gaqhf
                        if (_BranchTargetConnector != null)
1559
                        {
1560
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1561
                        }
1562
                        else
1563
                        {
1564
                            placeRunInputs.AddPoint(point[0], point[1]);
1565
                        }
1566
                        
1567 335b7a24 gaqhf
                    }
1568 6b298450 gaqhf
                    else
1569 335b7a24 gaqhf
                    {
1570 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
1571
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1572 65a1ed4b gaqhf
                        else if (_SameRunTargetSymbol != null)
1573 6b298450 gaqhf
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1574
                        else
1575
                            placeRunInputs.AddPoint(point[0], point[1]);
1576 335b7a24 gaqhf
                    }
1577 6b298450 gaqhf
                }
1578
                else if (i == points.Count - 1)
1579
                {
1580
                    if (IsStart)
1581 335b7a24 gaqhf
                    {
1582 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
1583
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
1584
                        else if (_SameRunTargetSymbol != null)
1585
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
1586 335b7a24 gaqhf
                        else
1587
                            placeRunInputs.AddPoint(point[0], point[1]);
1588
                    }
1589 6b298450 gaqhf
                    else
1590 335b7a24 gaqhf
                    {
1591 f9125a54 gaqhf
                        if (_BranchTargetConnector != null)
1592
                        {
1593
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
1594
                        }
1595 b2d1c1aa gaqhf
                        else
1596
                        {
1597
                            placeRunInputs.AddPoint(point[0], point[1]);
1598
                        }
1599 335b7a24 gaqhf
                    }
1600 6b298450 gaqhf
                }
1601
                else
1602
                    placeRunInputs.AddPoint(point[0], point[1]);
1603
            }
1604
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
1605
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1606 335b7a24 gaqhf
1607 6b298450 gaqhf
            if (_LMConnector != null)
1608
            {
1609
                if (_SameRunTargetConnector != null)
1610
                {
1611
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
1612
                }
1613
                else
1614
                {
1615
                    foreach (var item in lines)
1616
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
1617 335b7a24 gaqhf
                }
1618
1619 6b298450 gaqhf
                _LMConnector.Commit();
1620
                ReleaseCOMObjects(_LMConnector);
1621 335b7a24 gaqhf
            }
1622
1623 6b298450 gaqhf
            ReleaseCOMObjects(placeRunInputs);
1624
            ReleaseCOMObjects(_LMAItem);
1625
            if (_BranchTargetConnector != null)
1626
                ReleaseCOMObjects(_BranchTargetConnector);
1627
            if (_SameRunTargetConnector != null)
1628
                ReleaseCOMObjects(_SameRunTargetConnector);
1629
            if (_SameRunTargetSymbol != null)
1630
                ReleaseCOMObjects(_SameRunTargetSymbol);
1631 335b7a24 gaqhf
            foreach (var item in connectorVertices)
1632
                ReleaseCOMObjects(item.Key);
1633 6b298450 gaqhf
            foreach (var item in branchConnectorVertices)
1634
                ReleaseCOMObjects(item.Key);
1635 335b7a24 gaqhf
        }
1636
1637 74752074 gaqhf
        /// <summary>
1638
        /// EndBreak 모델링 메서드
1639
        /// </summary>
1640
        /// <param name="endBreak"></param>
1641 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
1642 335b7a24 gaqhf
        {
1643 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
1644 1ab9a205 gaqhf
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
1645
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
1646 3165c259 gaqhf
1647 1ab9a205 gaqhf
            if (targetLMConnector != null)
1648 10c7195c gaqhf
            {
1649 1ab9a205 gaqhf
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1650
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1651 2a4872ec gaqhf
            }
1652 1ab9a205 gaqhf
            
1653 f31645b6 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
1654 2a4872ec gaqhf
        }
1655 b9e9f4c8 gaqhf
1656 02480ac1 gaqhf
        private LMConnector ReModelingLMConnector(LMConnector connector)
1657
        {
1658 de97eaaa gaqhf
            string symbolPath = string.Empty;
1659
            #region get symbol path
1660
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
1661
            foreach (LMRepresentation rep in modelItem.Representations)
1662
            {
1663
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1664
                {
1665
                    symbolPath = rep.get_FileName();
1666
                    break;
1667
                }
1668
            }
1669
            #endregion
1670
1671 02480ac1 gaqhf
            LMConnector newConnector = null;
1672
            dynamic OID = connector.get_GraphicOID();
1673
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1674
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1675
            int verticesCount = lineStringGeometry.VertexCount;
1676
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1677 de97eaaa gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1678 02480ac1 gaqhf
1679
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
1680
            {
1681
                double[] vertices = null;
1682
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1683
                double x = 0;
1684
                double y = 0;
1685
                lineStringGeometry.GetVertex(1, ref x, ref y);
1686
1687
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
1688
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
1689
1690
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
1691
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1692
            }
1693
            else
1694
            {
1695
                List<double[]> vertices = new List<double[]>();
1696
                for (int i = 1; i <= verticesCount; i++)
1697
                {
1698
                    double x = 0;
1699
                    double y = 0;
1700
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1701
                    vertices.Add(new double[] { x, y });
1702
                }
1703
1704
                for (int i = 0; i < vertices.Count; i++)
1705
                {
1706
                    double[] points = vertices[i];
1707
                    if (i == 0)
1708
                    {
1709
                        if (connector.ConnectItem1SymbolObject != null)
1710
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
1711
                        else
1712
                            placeRunInputs.AddPoint(points[0], points[1]);
1713
                    }
1714
                    else if (i == vertices.Count - 1)
1715
                    {
1716
                        if (connector.ConnectItem2SymbolObject != null)
1717
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
1718
                        else
1719
                            placeRunInputs.AddPoint(points[0], points[1]);
1720
                    }
1721
                    else
1722
                        placeRunInputs.AddPoint(points[0], points[1]);
1723
                }
1724
1725
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID);
1726
1727
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
1728
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1729
1730
                foreach (var line in lines)
1731
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
1732
            }
1733
1734
1735
            return newConnector;
1736
        }
1737
1738 74752074 gaqhf
        /// <summary>
1739 53c81765 gaqhf
        /// SpecBreak Modeling 메서드
1740
        /// </summary>
1741
        /// <param name="specBreak"></param>
1742
        private void SpecBreakModeling(SpecBreak specBreak)
1743
        {
1744
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
1745
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
1746
1747
            if (upStreamObj != null &&
1748
                downStreamObj != null)
1749
            {
1750 1ab9a205 gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
1751
1752
                if (targetLMConnector != null)
1753 53c81765 gaqhf
                {
1754 16584d30 gaqhf
                    foreach (var attribute in specBreak.ATTRIBUTES)
1755 53c81765 gaqhf
                    {
1756 16584d30 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
1757
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
1758
                        {
1759
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
1760
                            Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
1761
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
1762 53c81765 gaqhf
1763 16584d30 gaqhf
                            if (_LmLabelPersist != null)
1764
                            {
1765
                                ReleaseCOMObjects(_LmLabelPersist);
1766
                            }
1767
                        }
1768
                    }
1769 1ab9a205 gaqhf
                    ReleaseCOMObjects(targetLMConnector);
1770
                }
1771
            }
1772
        }
1773 53c81765 gaqhf
1774 1ab9a205 gaqhf
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
1775
        {
1776
            LMConnector targetConnector = null;
1777
            Symbol targetSymbol = targetObj as Symbol;
1778
            Symbol connectedSymbol = connectedObj as Symbol;
1779
            Line targetLine = targetObj as Line;
1780
            Line connectedLine = connectedObj as Line;
1781
            if (targetSymbol != null && connectedSymbol != null)
1782
            {
1783
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
1784
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
1785
1786
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
1787
                {
1788
                    if (connector.get_ItemStatus() != "Active")
1789
                        continue;
1790
1791
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
1792
                    {
1793
                        targetConnector = connector;
1794
                        break;
1795
                    }
1796
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
1797
                    {
1798
                        targetConnector = connector;
1799
                        break;
1800 53c81765 gaqhf
                    }
1801
                }
1802 1ab9a205 gaqhf
1803
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
1804 53c81765 gaqhf
                {
1805 1ab9a205 gaqhf
                    if (connector.get_ItemStatus() != "Active")
1806
                        continue;
1807 53c81765 gaqhf
1808 1ab9a205 gaqhf
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
1809
                    {
1810
                        targetConnector = connector;
1811
                        break;
1812
                    }
1813
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
1814
                    {
1815
                        targetConnector = connector;
1816
                        break;
1817 53c81765 gaqhf
                    }
1818
                }
1819 1ab9a205 gaqhf
1820
                ReleaseCOMObjects(targetLMSymbol);
1821
                ReleaseCOMObjects(connectedLMSymbol);
1822
            }
1823
            else if (targetLine != null && connectedLine != null)
1824
            {
1825
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
1826
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
1827
1828
                if (targetModelItem != null && connectedModelItem != null)
1829 53c81765 gaqhf
                {
1830 1ab9a205 gaqhf
                    foreach (LMRepresentation rep in targetModelItem.Representations)
1831 53c81765 gaqhf
                    {
1832 1ab9a205 gaqhf
                        if (targetConnector != null)
1833
                            break;
1834 53c81765 gaqhf
1835 1ab9a205 gaqhf
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1836 53c81765 gaqhf
                        {
1837 1ab9a205 gaqhf
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1838
1839
                            if (IsConnected(_LMConnector, connectedModelItem))
1840
                                targetConnector = _LMConnector;
1841
                            else
1842
                                ReleaseCOMObjects(_LMConnector);
1843 53c81765 gaqhf
                        }
1844
                    }
1845 1ab9a205 gaqhf
1846
                    ReleaseCOMObjects(targetModelItem);
1847 53c81765 gaqhf
                }
1848 1ab9a205 gaqhf
            }
1849
            else
1850
            {
1851
                LMSymbol connectedLMSymbol = connectedSymbol != null ? 
1852
                    dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId) : dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
1853
                LMModelItem targetModelItem = targetLine != null ?
1854
                    dataSource.GetModelItem(targetLine.SPPID.ModelItemId) : dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
1855
                if (connectedLMSymbol != null && targetModelItem != null)
1856 53c81765 gaqhf
                {
1857 1ab9a205 gaqhf
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
1858
                    {
1859
                        if (IsConnected(connector, targetModelItem))
1860
                        {
1861
                            targetConnector = connector;
1862
                            break;
1863
                        }
1864
                    }
1865 53c81765 gaqhf
1866 1ab9a205 gaqhf
                    if (targetConnector == null)
1867 53c81765 gaqhf
                    {
1868 1ab9a205 gaqhf
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
1869 53c81765 gaqhf
                        {
1870 1ab9a205 gaqhf
                            if (IsConnected(connector, targetModelItem))
1871 53c81765 gaqhf
                            {
1872 1ab9a205 gaqhf
                                targetConnector = connector;
1873
                                break;
1874 53c81765 gaqhf
                            }
1875
                        }
1876
                    }
1877
                }
1878
1879 1ab9a205 gaqhf
            }
1880 02480ac1 gaqhf
1881 1ab9a205 gaqhf
            return targetConnector;
1882
        }
1883 53c81765 gaqhf
1884 1ab9a205 gaqhf
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
1885
        {
1886
            bool result = false;
1887
1888
            foreach (LMRepresentation rep in modelItem.Representations)
1889
            {
1890
                if (result)
1891
                    break;
1892
1893
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1894
                {
1895
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1896
1897
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
1898
                        connector.ConnectItem1SymbolObject != null &&
1899
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
1900 53c81765 gaqhf
                    {
1901 1ab9a205 gaqhf
                        result = true;
1902
                        ReleaseCOMObjects(_LMConnector);
1903
                        break;
1904
                    }
1905
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
1906
                        connector.ConnectItem2SymbolObject != null &&
1907
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
1908
                    {
1909
                        result = true;
1910
                        ReleaseCOMObjects(_LMConnector);
1911
                        break;
1912
                    }
1913
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
1914
                        connector.ConnectItem1SymbolObject != null &&
1915
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
1916
                    {
1917
                        result = true;
1918
                        ReleaseCOMObjects(_LMConnector);
1919
                        break;
1920
                    }
1921
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
1922
                        connector.ConnectItem2SymbolObject != null &&
1923
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
1924
                    {
1925
                        result = true;
1926
                        ReleaseCOMObjects(_LMConnector);
1927
                        break;
1928 53c81765 gaqhf
                    }
1929
1930 1ab9a205 gaqhf
                    ReleaseCOMObjects(_LMConnector);
1931
                }
1932 53c81765 gaqhf
            }
1933 1ab9a205 gaqhf
1934
1935
            return result;
1936 53c81765 gaqhf
        }
1937
1938
        /// <summary>
1939 74752074 gaqhf
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
1940
        /// </summary>
1941
        /// <param name="fromModelItemId"></param>
1942
        /// <param name="toModelItemId"></param>
1943 335b7a24 gaqhf
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
1944
        {
1945 310aeb31 gaqhf
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
1946
            _LMAItem item1 = modelItem1.AsLMAItem();
1947
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
1948
            _LMAItem item2 = modelItem2.AsLMAItem();
1949
            
1950 335b7a24 gaqhf
            // item2가 item1으로 조인
1951
            try
1952
            {
1953
                _placement.PIDJoinRuns(ref item1, ref item2);
1954 65a1ed4b gaqhf
                item1.Commit();
1955
                item2.Commit();
1956 3939eebf gaqhf
1957
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
1958
                foreach (var line in lines)
1959
                    line.SPPID.ModelItemId = toModelItemId;
1960 335b7a24 gaqhf
            }
1961
            catch (Exception ex)
1962
            {
1963
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1964
            }
1965
            finally
1966
            {
1967 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem1);
1968
                ReleaseCOMObjects(item1);
1969
                ReleaseCOMObjects(modelItem2);
1970
                ReleaseCOMObjects(item2);
1971 335b7a24 gaqhf
            }
1972
        }
1973
1974 74752074 gaqhf
        /// <summary>
1975
        /// PipeRun을 자동으로 Join하는 메서드
1976
        /// </summary>
1977
        /// <param name="modelItemId"></param>
1978 335b7a24 gaqhf
        private void AutoJoinPipeRun(string modelItemId)
1979
        {
1980 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
1981
            _LMAItem item = modelItem.AsLMAItem();
1982 65a1ed4b gaqhf
            try
1983
            {
1984
                string modelitemID = item.Id;
1985
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
1986
                string afterModelItemID = item.Id;
1987 5a83fda2 gaqhf
                
1988 65a1ed4b gaqhf
                if (modelitemID != afterModelItemID)
1989
                {
1990
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
1991
                    foreach (var line in lines)
1992
                        line.SPPID.ModelItemId = afterModelItemID;
1993
                }
1994
                item.Commit();
1995
            }
1996
            catch (Exception ex)
1997
            {
1998
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1999
            }
2000
            finally
2001
            {
2002 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
2003
                ReleaseCOMObjects(item);
2004 65a1ed4b gaqhf
            }
2005 335b7a24 gaqhf
        }
2006
2007 74752074 gaqhf
        /// <summary>
2008
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
2009
        /// </summary>
2010
        /// <param name="run"></param>
2011 335b7a24 gaqhf
        private void JoinRunLine(LineRun run)
2012
        {
2013
            string modelItemId = string.Empty;
2014
            foreach (var item in run.RUNITEMS)
2015
            {
2016
                if (item.GetType() == typeof(Line))
2017
                {
2018
                    Line line = item as Line;
2019 1ba9c671 gaqhf
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
2020
                    modelItemId = line.SPPID.ModelItemId;
2021 f31645b6 gaqhf
2022
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2023 335b7a24 gaqhf
                }
2024
            }
2025
        }
2026
2027 74752074 gaqhf
        /// <summary>
2028
        /// PipeRun의 좌표를 가져오는 메서드
2029
        /// </summary>
2030
        /// <param name="modelId"></param>
2031
        /// <returns></returns>
2032 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2033
        {
2034
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2035 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2036
2037
            if (modelItem != null)
2038 5e6ecf05 gaqhf
            {
2039 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
2040 5e6ecf05 gaqhf
                {
2041
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2042
                    {
2043
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2044
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2045
                        dynamic OID = rep.get_GraphicOID();
2046 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2047 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2048
                        int verticesCount = lineStringGeometry.VertexCount;
2049
                        double[] vertices = null;
2050
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2051
                        for (int i = 0; i < verticesCount; i++)
2052
                        {
2053
                            double x = 0;
2054
                            double y = 0;
2055
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2056 335b7a24 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
2057 5e6ecf05 gaqhf
                        }
2058
                    }
2059
                }
2060
2061 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
2062 5e6ecf05 gaqhf
            }
2063
2064
            return connectorVertices;
2065
        }
2066
2067 7c7bcd10 gaqhf
        /// <summary>
2068
        /// LMConnector들을 가져온다.
2069
        /// </summary>
2070
        /// <param name="modelId"></param>
2071
        /// <returns></returns>
2072 53c81765 gaqhf
        private List<LMConnector> GetConnectors(string modelId)
2073
        {
2074
            List<LMConnector> connectors = new List<LMConnector>();
2075
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2076
2077
            if (modelItem != null)
2078
            {
2079
                foreach (LMRepresentation rep in modelItem.Representations)
2080
                {
2081
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2082
                    {
2083
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2084
                        connectors.Add(_LMConnector);
2085
                    }
2086
                }
2087
2088
                ReleaseCOMObjects(modelItem);
2089
            }
2090
2091
            return connectors;
2092
        }
2093
2094 74752074 gaqhf
        /// <summary>
2095
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함
2096
        /// </summary>
2097
        /// <param name="connectorVertices"></param>
2098
        /// <param name="connX"></param>
2099
        /// <param name="connY"></param>
2100
        /// <param name="x2"></param>
2101
        /// <param name="y2"></param>
2102
        /// <returns></returns>
2103 56bc67e1 gaqhf
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
2104 5e6ecf05 gaqhf
        {
2105
            double length = double.MaxValue;
2106
            LMConnector targetConnector = null;
2107
            foreach (var item in connectorVertices)
2108
            {
2109
                List<double[]> points = item.Value;
2110
                for (int i = 0; i < points.Count - 1; i++)
2111
                {
2112
                    double[] point1 = points[i];
2113
                    double[] point2 = points[i + 1];
2114
2115 335b7a24 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
2116
                    double minLineX = Math.Min(point1[0], point2[0]);
2117
                    double maxLineY = Math.Max(point1[1], point2[1]);
2118
                    double minLineY = Math.Min(point1[1], point2[1]);
2119
2120
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2121
2122 56bc67e1 gaqhf
                    // 두직선의 교차점
2123
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
2124
                    if (crossingPoint != null)
2125 5e6ecf05 gaqhf
                    {
2126 30a9ffce gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
2127 335b7a24 gaqhf
                        if (length >= distance)
2128 30a9ffce gaqhf
                        {
2129 335b7a24 gaqhf
                            if (slope == SlopeType.Slope &&
2130
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2131
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2132
                            {
2133
                                targetConnector = item.Key;
2134
                                length = distance;
2135
                            }
2136
                            else if (slope == SlopeType.HORIZONTAL &&
2137
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2138
                            {
2139
                                targetConnector = item.Key;
2140
                                length = distance;
2141
                            }
2142
                            else if (slope == SlopeType.VERTICAL &&
2143
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2144
                            {
2145
                                targetConnector = item.Key;
2146
                                length = distance;
2147
                            }
2148 30a9ffce gaqhf
                        }
2149 5e6ecf05 gaqhf
                    }
2150
                }
2151 c3d2e266 gaqhf
2152
2153
            }
2154
2155
            if (targetConnector == null)
2156
            {
2157
                foreach (var item in connectorVertices)
2158
                {
2159
                    List<double[]> points = item.Value;
2160
                    foreach (var point in points)
2161
                    {
2162
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
2163
                        if (length >= distance)
2164
                        {
2165
                            targetConnector = item.Key;
2166
                            length = distance;
2167
                        }
2168
                    }
2169
                }
2170
2171 5e6ecf05 gaqhf
            }
2172
2173
            return targetConnector;
2174
        }
2175
2176 74752074 gaqhf
        /// <summary>
2177
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순)
2178
        /// </summary>
2179
        /// <param name="connectorVertices"></param>
2180
        /// <param name="connX"></param>
2181
        /// <param name="connY"></param>
2182
        /// <returns></returns>
2183 ac78b508 gaqhf
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2184
        {
2185
            double length = double.MaxValue;
2186
            LMConnector targetConnector = null;
2187
            foreach (var item in connectorVertices)
2188
            {
2189
                List<double[]> points = item.Value;
2190
2191
                foreach (double[] point in points)
2192
                {
2193
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2194
                    if (length >= distance)
2195
                    {
2196
                        targetConnector = item.Key;
2197
                        length = distance;
2198
                    }
2199
                }
2200
            }
2201
2202
            return targetConnector;
2203
        }
2204
2205 74752074 gaqhf
        /// <summary>
2206
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2207
        /// </summary>
2208
        /// <param name="connectorVertices"></param>
2209
        /// <param name="connX"></param>
2210
        /// <param name="connY"></param>
2211
        /// <returns></returns>
2212 68464385 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2213
        {
2214
            double length = double.MaxValue;
2215
            LMConnector targetConnector = null;
2216
            foreach (var item in connectorVertices)
2217
            {
2218
                List<double[]> points = item.Value;
2219
                for (int i = 0; i < points.Count - 1; i++)
2220
                {
2221
                    double[] point1 = points[i];
2222
                    double[] point2 = points[i + 1];
2223
                    double x1 = Math.Min(point1[0], point2[0]);
2224
                    double y1 = Math.Min(point1[1], point2[1]);
2225
                    double x2 = Math.Max(point1[0], point2[0]);
2226
                    double y2 = Math.Max(point1[1], point2[1]);
2227
2228
                    if ((x1 <= connX && x2 >= connX) ||
2229
                        (y1 <= connY && y2 >= connY))
2230
                    {
2231
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2232
                        if (length >= distance)
2233
                        {
2234
                            targetConnector = item.Key;
2235
                            length = distance;
2236
                        }
2237
2238
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2239
                        if (length >= distance)
2240
                        {
2241
                            targetConnector = item.Key;
2242
                            length = distance;
2243
                        }
2244
                    }
2245
                }
2246
            }
2247
2248
            // 못찾았을때.
2249
            length = double.MaxValue;
2250
            if (targetConnector == null)
2251
            {
2252
                foreach (var item in connectorVertices)
2253
                {
2254
                    List<double[]> points = item.Value;
2255
2256
                    foreach (double[] point in points)
2257
                    {
2258
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2259
                        if (length >= distance)
2260
                        {
2261
                            targetConnector = item.Key;
2262
                            length = distance;
2263
                        }
2264
                    }
2265
                }
2266
            }
2267
2268
            return targetConnector;
2269
        }
2270
2271 74752074 gaqhf
        /// <summary>
2272
        /// Line Number Symbol을 실제로 Modeling하는 메서드
2273
        /// </summary>
2274
        /// <param name="lineNumber"></param>
2275 cfda1fed gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
2276
        {
2277 f4880c6a gaqhf
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
2278
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2279 68464385 gaqhf
            LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
2280 f4880c6a gaqhf
            if (connectedLMConnector != null)
2281 10872260 gaqhf
            {
2282 b65a7e32 gaqhf
                double x = 0;
2283
                double y = 0;
2284
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
2285
2286
                Array points = new double[] { 0, x, y };
2287 f4880c6a gaqhf
                LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
2288 cfda1fed gaqhf
2289 f4880c6a gaqhf
                foreach (var item in connectorVertices)
2290
                    ReleaseCOMObjects(item.Key);
2291
                if (_LmLabelPresist != null)
2292
                {
2293 c3d2e266 gaqhf
                    _LmLabelPresist.Commit();
2294 f4880c6a gaqhf
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
2295
                    ReleaseCOMObjects(_LmLabelPresist);
2296 10872260 gaqhf
                }
2297 c3d2e266 gaqhf
                else
2298
                {
2299
2300
                }
2301 10872260 gaqhf
            }
2302 f31645b6 gaqhf
2303
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2304 cfda1fed gaqhf
        }
2305
2306 74752074 gaqhf
        /// <summary>
2307 b2d1c1aa gaqhf
        /// Flow Mark Modeling
2308
        /// </summary>
2309
        /// <param name="line"></param>
2310
        private void FlowMarkModeling(Line line)
2311
        {
2312 a0965e07 gaqhf
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
2313 b2d1c1aa gaqhf
            {
2314 47ad9a46 gaqhf
                SlopeType targetSlopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
2315 b2d1c1aa gaqhf
                string mappingPath = _ETCSetting.FlowMarkSymbolPath;
2316 47ad9a46 gaqhf
                double percent = line.FLOWMARK_PERCENT;
2317 b2d1c1aa gaqhf
                double tempX = 0;
2318
                double tempY = 0;
2319
2320 47ad9a46 gaqhf
                double gapX;
2321
                double gapY;
2322
                // ID2 기준의 Gap을 구함
2323
                if (percent == 0)
2324
                {
2325
                    gapX = 0;
2326
                    gapY = 0;
2327
                }
2328
                else
2329
                {
2330
                    gapX = Math.Abs(line.SPPID.START_X - line.SPPID.END_X) / 100 * percent;
2331
                    gapY = Math.Abs(line.SPPID.START_Y - line.SPPID.END_Y) / 100 * percent;
2332
                }
2333 b2d1c1aa gaqhf
2334 47ad9a46 gaqhf
                if (line.SPPID.START_X < line.SPPID.END_X)
2335
                    tempX = line.SPPID.START_X + gapX;
2336
                else
2337
                    tempX = line.SPPID.START_X - gapX;
2338 b2d1c1aa gaqhf
2339 47ad9a46 gaqhf
                if (line.SPPID.START_Y < line.SPPID.END_Y)
2340
                    tempY = line.SPPID.START_Y + gapY;
2341
                else
2342
                    tempY = line.SPPID.START_Y - gapY;
2343 b2d1c1aa gaqhf
2344 47ad9a46 gaqhf
                
2345
               
2346 b2d1c1aa gaqhf
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2347
                LMConnector _TargetItem = null;
2348
                double distance = double.MaxValue;
2349 47ad9a46 gaqhf
                double[] startPoint = null;
2350
                double[] endPoint = null;
2351
                // ID2의 기준 Gap으로 제일 가까운 Line 찾음(Slope도 같은조건)
2352 b2d1c1aa gaqhf
                foreach (var item in connectorVertices)
2353
                {
2354
                    for (int i = 0; i < item.Value.Count - 1; i++)
2355
                    {
2356
                        List<double[]> points = item.Value;
2357
                        double[] point1 = points[i];
2358
                        double[] point2 = points[i + 1];
2359
2360
                        SlopeType slopeType = SPPIDUtil.CalcSlope(point1[0], point1[1], point2[0], point2[1]);
2361 47ad9a46 gaqhf
                        if (slopeType == targetSlopeType)
2362 b2d1c1aa gaqhf
                        {
2363 47ad9a46 gaqhf
                            double result = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], tempX, tempY);
2364
                            if (result < distance)
2365 b2d1c1aa gaqhf
                            {
2366 47ad9a46 gaqhf
                                distance = result;
2367
                                _TargetItem = item.Key;
2368
2369
                                startPoint = point1;
2370
                                endPoint = point2;
2371 b2d1c1aa gaqhf
                            }
2372 47ad9a46 gaqhf
2373
                            result = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], tempX, tempY);
2374
                            if (result < distance)
2375 b2d1c1aa gaqhf
                            {
2376 47ad9a46 gaqhf
                                distance = result;
2377
                                _TargetItem = item.Key;
2378 b2d1c1aa gaqhf
2379 47ad9a46 gaqhf
                                startPoint = point1;
2380
                                endPoint = point2;
2381
                            }
2382 b2d1c1aa gaqhf
                        }
2383
                    }
2384
                }
2385
2386
                if (_TargetItem != null)
2387
                {
2388 47ad9a46 gaqhf
                    double x = 0;
2389
                    double y = 0;
2390
                    double angle = 0;
2391
                    // SPPID 기준의 Gap으로 실 좌표를 구함
2392
                    if (percent == 0)
2393
                    {
2394
                        gapX = 0;
2395
                        gapY = 0;
2396
                    }
2397
                    else
2398
                    {
2399
                        gapX = Math.Abs(startPoint[0] - endPoint[0]) / 100 * percent;
2400
                        gapY = Math.Abs(startPoint[1] - endPoint[1]) / 100 * percent;
2401
                    }
2402 b2d1c1aa gaqhf
2403 47ad9a46 gaqhf
                    if (startPoint[0] < endPoint[0])
2404
                        x = startPoint[0] + gapX;
2405
                    else
2406
                        x = startPoint[0] - gapX;
2407
2408
                    if (startPoint[1] < endPoint[1])
2409
                        y = startPoint[1] + gapY;
2410
                    else
2411
                        y = startPoint[1] - gapY;
2412
                    
2413
                    if (targetSlopeType == SlopeType.HORIZONTAL)
2414
                    {
2415
                        if (startPoint[0] < endPoint[0])
2416
                            angle = 0;
2417
                        else
2418
                            angle = Math.PI;
2419
                    }
2420
                    // 90 270
2421
                    else if (targetSlopeType == SlopeType.VERTICAL)
2422
                    {
2423
                        if (startPoint[1] < endPoint[1])
2424
                            angle = 90 * Math.PI / 180;
2425
                        else
2426
                            angle = 270 * Math.PI / 180;
2427
                    }
2428
2429
                    LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: 0, Rotation: angle, TargetItem: _TargetItem);
2430
                    
2431 b2d1c1aa gaqhf
                    if (_LMSymbol != null)
2432
                    {
2433
                        ReleaseCOMObjects(_LMSymbol);
2434
                    }
2435
                        
2436
                }
2437
2438
                foreach (var item in connectorVertices)
2439
                    ReleaseCOMObjects(item.Key);
2440
            }
2441
        }
2442
2443
        /// <summary>
2444 74752074 gaqhf
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
2445
        /// </summary>
2446
        /// <param name="lineNumber"></param>
2447 a7e9beec gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber)
2448
        {
2449 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
2450 a7e9beec gaqhf
            {
2451 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
2452 a7e9beec gaqhf
                {
2453 8634af60 gaqhf
                    if (item.GetType() == typeof(Symbol))
2454 a7e9beec gaqhf
                    {
2455 8634af60 gaqhf
                        Symbol symbol = item as Symbol;
2456
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2457
                        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
2458
2459
                        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2460
                        {
2461
                            foreach (var attribute in lineNumber.ATTRIBUTES)
2462
                            {
2463
                                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2464 b2d1c1aa gaqhf
                                if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2465 8634af60 gaqhf
                                {
2466
                                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
2467
                                    if (_LMAAttribute != null)
2468
                                    {
2469
                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2470
                                            _LMAAttribute.set_Value(attribute.VALUE);
2471
                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
2472
                                            _LMAAttribute.set_Value(attribute.VALUE);
2473
                                    }
2474
                                }
2475
                            }
2476
                            _LMModelItem.Commit();
2477
                        }
2478
                        if (_LMModelItem != null)
2479
                            ReleaseCOMObjects(_LMModelItem);
2480
                        if (_LMSymbol != null)
2481
                            ReleaseCOMObjects(_LMSymbol);
2482
                    }
2483
                    else if (item.GetType() == typeof(Line))
2484
                    {
2485
                        Line line = item as Line;
2486
                        if (line != null)
2487 a7e9beec gaqhf
                        {
2488 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2489
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2490 a7e9beec gaqhf
                            {
2491 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
2492
                                {
2493
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
2494 b2d1c1aa gaqhf
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2495 8634af60 gaqhf
                                    {
2496
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
2497
                                        if (_LMAAttribute != null)
2498
                                        {
2499
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2500
                                                _LMAAttribute.set_Value(attribute.VALUE);
2501
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
2502
                                                _LMAAttribute.set_Value(attribute.VALUE);
2503
                                            
2504
                                        }
2505
                                    }
2506
                                }
2507 68464385 gaqhf
                                _LMModelItem.Commit();
2508 a7e9beec gaqhf
                            }
2509 8634af60 gaqhf
                            if (_LMModelItem != null)
2510
                                ReleaseCOMObjects(_LMModelItem);
2511 a7e9beec gaqhf
                        }
2512
                    }
2513
                }
2514
            }
2515 f31645b6 gaqhf
2516
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2517 a7e9beec gaqhf
        }
2518
2519 74752074 gaqhf
        /// <summary>
2520
        /// Symbol Attribute 입력 메서드
2521
        /// </summary>
2522 73415441 gaqhf
        /// <param name="item"></param>
2523
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
2524 1efc25a3 gaqhf
        {
2525 ac78b508 gaqhf
            try
2526 1efc25a3 gaqhf
            {
2527 73415441 gaqhf
                // Object 아이템이 Symbol일 경우 Equipment일 경우 
2528
                string sRep = null;
2529
                if (targetItem.GetType() == typeof(Symbol))
2530
                    sRep = ((Symbol)targetItem).SPPID.RepresentationId;
2531
                else if (targetItem.GetType() == typeof(Equipment))
2532
                    sRep = ((Equipment)targetItem).SPPID.RepresentationId;
2533
                    
2534
                if (!string.IsNullOrEmpty(sRep))
2535 402ef5b1 gaqhf
                {
2536 73415441 gaqhf
                    LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
2537 310aeb31 gaqhf
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
2538 ea80efaa gaqhf
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
2539 402ef5b1 gaqhf
2540 73415441 gaqhf
                    foreach (var item in targetAttributes)
2541 65a1ed4b gaqhf
                    {
2542 ac78b508 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
2543 26c6f818 gaqhf
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
2544 ac78b508 gaqhf
                        {
2545
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
2546
                            if (_Attribute != null)
2547 73415441 gaqhf
                                _Attribute.set_Value(item.VALUE);
2548 ac78b508 gaqhf
                        }
2549 65a1ed4b gaqhf
                    }
2550 73415441 gaqhf
                    _LMModelItem.Commit();
2551
                    
2552 ea80efaa gaqhf
                    ReleaseCOMObjects(_Attributes);
2553
                    ReleaseCOMObjects(_LMModelItem);
2554 73415441 gaqhf
                    ReleaseCOMObjects(_LMSymbol);
2555 ac78b508 gaqhf
                }
2556
            }
2557
            catch (Exception ex)
2558
            {
2559
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2560 1efc25a3 gaqhf
            }
2561 f31645b6 gaqhf
2562
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2563 1efc25a3 gaqhf
        }
2564
2565 74752074 gaqhf
        /// <summary>
2566 16584d30 gaqhf
        /// Input SpecBreak Attribute
2567
        /// </summary>
2568
        /// <param name="specBreak"></param>
2569
        private void InputSpecBreakAttribute(SpecBreak specBreak)
2570
        {
2571
            try
2572
            {
2573
                object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2574
                object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2575
2576
                if (upStreamObj != null &&
2577
                    downStreamObj != null)
2578
                {
2579
                    LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2580
2581
                    if (targetLMConnector != null)
2582
                    {
2583
                        foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
2584
                        {
2585
                            string symbolPath = _LMLabelPersist.get_FileName();
2586
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
2587
                            if (mapping != null)
2588
                            {
2589
                                BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
2590
                                if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
2591
                                {
2592
                                    string[] values = attribute.VALUE.Split(new char[] { ',' });
2593
                                    if (values.Length == 2)
2594
                                    {
2595
                                        string upStreamValue = values[0];
2596
                                        string downStreamValue = values[1];
2597
2598
                                        InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
2599
                                    }
2600
                                }
2601
                            }
2602
                        }
2603
2604
                        ReleaseCOMObjects(targetLMConnector);
2605
                    }
2606
                }
2607
            }
2608
            catch (Exception ex)
2609
            {
2610
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2611
            }
2612
2613
            #region 내부에서만 쓰는 메서드
2614
            void InputAttributeForSpecBreak(object upStreamObj, object downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
2615
            {
2616
                try
2617
                {
2618
                    Symbol upStreamSymbol = upStreamObj as Symbol;
2619
                    Line upStreamLine = upStreamObj as Line;
2620
                    Symbol downStreamSymbol = downStreamObj as Symbol;
2621
                    Line downStreamLine = downStreamObj as Line;
2622
                    // 둘다 Line일 경우
2623
                    if (upStreamLine != null && downStreamLine != null)
2624
                    {
2625
                        InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
2626
                        InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
2627
                    }
2628
                    // 둘다 Symbol일 경우
2629
                    else if (upStreamSymbol != null && downStreamSymbol != null)
2630
                    {
2631
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
2632
                        LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
2633
                        LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
2634
2635
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
2636
                        {
2637
                            if (connector.get_ItemStatus() != "Active")
2638
                                continue;
2639
2640
                            if (connector.Id != zeroLenthConnector.Id)
2641
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2642
                        }
2643
2644
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
2645
                        {
2646
                            if (connector.get_ItemStatus() != "Active")
2647
                                continue;
2648
2649
                            if (connector.Id != zeroLenthConnector.Id)
2650
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2651
                        }
2652
2653
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
2654
                        {
2655
                            if (connector.get_ItemStatus() != "Active")
2656
                                continue;
2657
2658
                            if (connector.Id != zeroLenthConnector.Id)
2659
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2660
                        }
2661
2662
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
2663
                        {
2664
                            if (connector.get_ItemStatus() != "Active")
2665
                                continue;
2666
2667
                            if (connector.Id != zeroLenthConnector.Id)
2668
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2669
                        }
2670
2671
                        ReleaseCOMObjects(zeroLenthConnector);
2672
                        ReleaseCOMObjects(upStreamLMSymbol);
2673
                        ReleaseCOMObjects(downStreamLMSymbol);
2674
                    }
2675
                    else if (upStreamSymbol != null && downStreamLine != null)
2676
                    {
2677
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
2678
                        InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
2679
                        LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
2680
2681
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
2682
                        {
2683
                            if (connector.get_ItemStatus() != "Active")
2684
                                continue;
2685
2686
                            if (connector.Id != zeroLenthConnector.Id)
2687
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2688
                        }
2689
2690
                        foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
2691
                        {
2692
                            if (connector.get_ItemStatus() != "Active")
2693
                                continue;
2694
2695
                            if (connector.Id != zeroLenthConnector.Id)
2696
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
2697
                        }
2698
2699
                        ReleaseCOMObjects(zeroLenthConnector);
2700
                        ReleaseCOMObjects(upStreamLMSymbol);
2701
                    }
2702
                    else if (upStreamLine != null && downStreamSymbol != null)
2703
                    {
2704
                        LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
2705
                        InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
2706
                        LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
2707
2708
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
2709
                        {
2710
                            if (connector.get_ItemStatus() != "Active")
2711
                                continue;
2712
2713
                            if (connector.Id != zeroLenthConnector.Id)
2714
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2715
                        }
2716
2717
                        foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
2718
                        {
2719
                            if (connector.get_ItemStatus() != "Active")
2720
                                continue;
2721
2722
                            if (connector.Id != zeroLenthConnector.Id)
2723
                                InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
2724
                        }
2725
2726
                        ReleaseCOMObjects(zeroLenthConnector);
2727
                        ReleaseCOMObjects(downStreamLMSymbol);
2728
                    }
2729
                }
2730
                catch (Exception ex)
2731
                {
2732
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2733
                }
2734
            }
2735
2736
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
2737
            {
2738
                try
2739
                {
2740
                    LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2741
                    if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2742
                    {
2743
                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
2744
                        if (_LMAAttribute != null)
2745
                        {
2746
                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2747
                                _LMAAttribute.set_Value(value);
2748
                            else if (_LMAAttribute.get_Value() != value)
2749
                                _LMAAttribute.set_Value(value);
2750
                        }
2751
2752
                        _LMModelItem.Commit();
2753
                    }
2754
                    if (_LMModelItem != null)
2755
                        ReleaseCOMObjects(_LMModelItem);
2756
                }
2757
                catch (Exception ex)
2758
                {
2759
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2760
                }
2761
            }
2762
2763
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
2764
            {
2765
                try
2766
                {
2767
                    LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
2768
                    if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
2769
                    {
2770
                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
2771
                        if (_LMAAttribute != null)
2772
                        {
2773
                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
2774
                                _LMAAttribute.set_Value(value);
2775
                            else if (_LMAAttribute.get_Value() != value)
2776
                                _LMAAttribute.set_Value(value);
2777
                        }
2778
2779
                        _LMModelItem.Commit();
2780
                    }
2781
                    if (_LMModelItem != null)
2782
                        ReleaseCOMObjects(_LMModelItem);
2783
                }
2784
                catch (Exception ex)
2785
                {
2786
                    System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
2787
                }
2788
            }
2789
            #endregion
2790
        }
2791
2792
        /// <summary>
2793 74752074 gaqhf
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
2794
        /// </summary>
2795
        /// <param name="text"></param>
2796 cfda1fed gaqhf
        private void TextModeling(Text text)
2797
        {
2798 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
2799
            try
2800
            {
2801 8b069d9f gaqhf
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
2802
                if (text.ASSOCIATION)
2803 ea80efaa gaqhf
                {
2804
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
2805
                    if (owner.GetType() == typeof(Symbol))
2806
                    {
2807
                        Symbol symbol = owner as Symbol;
2808
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2809
                        if (_LMSymbol != null)
2810
                        {
2811
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
2812
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
2813
                            AttributeMapping mapping = null;
2814
                            foreach (var attribute in attributes)
2815
                            {
2816 26c6f818 gaqhf
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
2817
                                    continue;
2818
2819 ea80efaa gaqhf
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
2820
                                if (mapping != null)
2821
                                    break;  
2822
                            }
2823
2824
                            if (mapping != null)
2825
                            {
2826 1a3a74a8 gaqhf
                                double x = 0;
2827
                                double y = 0;
2828
2829 b65a7e32 gaqhf
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
2830
                                Array array = new double[] { 0, x, y };
2831 1a3a74a8 gaqhf
2832 1ba9c671 gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2833 ea80efaa gaqhf
                                if (_LMLabelPersist!=null)
2834
                                {
2835 f9125a54 gaqhf
                                    _LMLabelPersist.Commit();
2836 ea80efaa gaqhf
                                    ReleaseCOMObjects(_LMLabelPersist);
2837
                                }
2838
                            }
2839
                        }
2840
                    }
2841
                    else if (owner.GetType() == typeof(Line))
2842
                    {
2843
2844
                    }
2845
                }
2846
                else
2847
                {
2848
                    LMItemNote _LMItemNote = null;
2849
                    LMAAttribute _LMAAttribute = null;
2850
2851 b65a7e32 gaqhf
                    double x = 0;
2852
                    double y = 0;
2853
2854
                    CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
2855
2856
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
2857 ea80efaa gaqhf
                    _LMSymbol.Commit();
2858
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
2859
                    _LMItemNote.Commit();
2860
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
2861
                    _LMAAttribute.set_Value(text.VALUE);
2862
                    _LMItemNote.Commit();
2863
2864
                    if (_LMAAttribute != null)
2865
                        ReleaseCOMObjects(_LMAAttribute);
2866
                    if (_LMItemNote != null)
2867
                        ReleaseCOMObjects(_LMItemNote);
2868
                }
2869 6b298450 gaqhf
            }
2870
            catch (Exception ex)
2871
            {
2872 cfda1fed gaqhf
2873 6b298450 gaqhf
            }
2874
            finally
2875
            {
2876
                if (_LMSymbol != null)
2877
                    ReleaseCOMObjects(_LMSymbol);
2878
            }
2879 f31645b6 gaqhf
2880
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2881 cfda1fed gaqhf
        }
2882
2883 74752074 gaqhf
        /// <summary>
2884
        /// Note Modeling
2885
        /// </summary>
2886
        /// <param name="note"></param>
2887 cfda1fed gaqhf
        private void NoteModeling(Note note)
2888
        {
2889 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
2890
            LMItemNote _LMItemNote = null;
2891
            LMAAttribute _LMAAttribute = null;
2892
2893
            try
2894
            {
2895 b65a7e32 gaqhf
                double x = 0;
2896
                double y = 0;
2897
2898
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
2899
2900
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
2901 6b298450 gaqhf
                _LMSymbol.Commit();
2902
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
2903
                _LMItemNote.Commit();
2904
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
2905
                _LMAAttribute.set_Value(note.VALUE);
2906
                _LMItemNote.Commit();
2907
            }
2908
            catch (Exception ex)
2909
            {
2910 cfda1fed gaqhf
2911 6b298450 gaqhf
            }
2912
            finally
2913
            {
2914
                if (_LMAAttribute != null)
2915
                    ReleaseCOMObjects(_LMAAttribute);
2916
                if (_LMItemNote != null)
2917
                    ReleaseCOMObjects(_LMItemNote);
2918
                if (_LMSymbol != null)
2919
                    ReleaseCOMObjects(_LMSymbol);
2920
            }
2921 f31645b6 gaqhf
2922
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount);
2923 cfda1fed gaqhf
        }
2924
2925 74752074 gaqhf
        /// <summary>
2926
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
2927
        /// </summary>
2928
        /// <param name="x"></param>
2929
        /// <param name="y"></param>
2930
        /// <param name="originX"></param>
2931
        /// <param name="originY"></param>
2932
        /// <param name="SPPIDLabelLocation"></param>
2933
        /// <param name="location"></param>
2934 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
2935
        {
2936
            if (location == Location.None)
2937
            {
2938
                x = originX;
2939
                y = originY;
2940
            }
2941
            else
2942
            {
2943
                if (location.HasFlag(Location.Center))
2944
                {
2945
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
2946
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
2947
                }
2948
2949
                if (location.HasFlag(Location.Left))
2950
                    x = SPPIDLabelLocation.X1;
2951
                else if (location.HasFlag(Location.Right))
2952
                    x = SPPIDLabelLocation.X2;
2953
2954
                if (location.HasFlag(Location.Down))
2955
                    y = SPPIDLabelLocation.Y1;
2956
                else if (location.HasFlag(Location.Up))
2957
                    y = SPPIDLabelLocation.Y2;
2958
            }
2959
        }
2960 5a4b8f32 gaqhf
2961 74752074 gaqhf
        /// <summary>
2962 4d2571ab gaqhf
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
2963
        /// 1. Angle Valve
2964
        /// 2. 3개로 이루어진 Symbol Group
2965
        /// </summary>
2966
        /// <returns></returns>
2967
        private List<Symbol> GetPrioritySymbol()
2968
        {
2969
            DataTable symbolTable = document.SymbolTable;
2970
2971
            // List에 순서대로 쌓는다.
2972
            List<Symbol> symbols = new List<Symbol>();
2973
            // Angle Valve 부터
2974
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2))
2975
            {
2976
                if (!symbols.Contains(symbol))
2977
                {
2978
                    double originX = 0;
2979
                    double originY = 0;
2980
2981
                    // ID2 Table에서 Original Point 가져옴.
2982
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}",symbol.DBUID))[0]["OriginalPoint"].ToString();
2983
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
2984
2985
                    SlopeType slopeType1 = SlopeType.None;
2986
                    SlopeType slopeType2 = SlopeType.None;
2987
                    foreach (Connector connector in symbol.CONNECTORS)
2988
                    {
2989
                        double connectorX = 0;
2990
                        double connectorY = 0;
2991
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
2992
                        if (slopeType1 == SlopeType.None)
2993
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
2994
                        else
2995
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
2996
                    }
2997
2998
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
2999
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3000
                        symbols.Add(symbol);
3001
                }
3002
            }
3003
3004
            // 3개의 Symbol이 뭉쳐 있을 때
3005
            foreach (var item in document.SYMBOLS)
3006
            {
3007
                List<Symbol> group = new List<Symbol>();
3008
                SPPIDUtil.FindConnectedSymbolGroup(document, item, group);
3009
                if (group.Count == 3)
3010
                {
3011
                    Symbol symbol = SPPIDUtil.FindCenterAtThreeSymbols(document, group);
3012
                    if (!symbols.Contains(symbol))
3013
                        symbols.Add(symbol);
3014
                }
3015
            }
3016
3017
            // Connection Point가 3개 이상
3018
            foreach (var symbol in document.SYMBOLS)
3019
                if (symbol.CONNECTORS.Count > 2 && !symbols.Contains(symbol))
3020
                    symbols.Add(symbol);
3021
3022
            return symbols;
3023
        }
3024
3025
        /// <summary>
3026 b2d1c1aa gaqhf
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
3027
        /// </summary>
3028
        /// <param name="graphicOID"></param>
3029
        /// <param name="milliseconds"></param>
3030
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
3031
        {
3032
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
3033
            {
3034
                double minX = 0;
3035
                double minY = 0;
3036
                double maxX = 0;
3037
                double maxY = 0;
3038
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
3039
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
3040
3041
                Thread.Sleep(milliseconds);
3042
            }
3043
        }
3044
3045
        /// <summary>
3046 74752074 gaqhf
        /// ComObject를 Release
3047
        /// </summary>
3048
        /// <param name="objVars"></param>
3049 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
3050
        {
3051
            int intNewRefCount = 0;
3052
            foreach (object obj in objVars)
3053
            {
3054
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
3055
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
3056
            }
3057
        }
3058 cfda1fed gaqhf
    }
3059
}
클립보드 이미지 추가 (최대 크기: 500 MB)