프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 88bac50c

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