프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ dfac4553

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Data;
7
using Llama;
8
using Plaice;
9
using Ingr.RAD2D.Interop.RAD2D;
10
using Ingr.RAD2D.Internal;
11
using Ingr.RAD2D.Helper;
12
using Converter.BaseModel;
13
using Converter.SPPID.Model;
14
using Converter.SPPID.Properties;
15
using Converter.SPPID.Util;
16
using Converter.SPPID.DB;
17
using Ingr.RAD2D.MacroControls.CmdCtrl;
18
using Ingr.RAD2D;
19
using System.Windows;
20
using System.Threading;
21
using System.Drawing;
22
using Microsoft.VisualBasic;
23
using Newtonsoft.Json;
24
using DevExpress.XtraSplashScreen;
25
namespace Converter.SPPID
26
{
27
    public class AutoModeling
28
    {
29
        Placement _placement;
30
        LMADataSource dataSource;
31
        LMDrawing currentDrawing;
32
        dynamic newDrawing;
33
        dynamic application;
34
        Ingr.RAD2D.Application radApp;
35
        SPPID_Document document;
36
        ETCSetting _ETCSetting;
37

    
38
        public string DocumentLabelText { get; set; }
39

    
40
        List<Line> NewBranchLines = new List<Line>();
41
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42
        List<string> ZeroLengthModelItemID = new List<string>();
43
        List<Symbol> prioritySymbols;
44

    
45
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
46
        {
47
            this.document = document;
48
            this.application = application;
49
            this.radApp = radApp;
50
            this._ETCSetting = ETCSetting.GetInstance();
51
        }
52

    
53
        private void SetSystemEditingCommand(bool value)
54
        {
55
            foreach (var item in radApp.Commands)
56
            {
57
                if (item.Argument == "SystemEditingCmd.SystemEditing")
58
                {
59
                    if (item.Checked != value)
60
                    {
61
                        radApp.RunMacro("systemeditingcmd.dll");
62
                        break;
63
                    }
64

    
65
                }
66
            }
67
        }
68

    
69
        /// <summary>
70
        /// 도면 단위당 실행되는 메서드
71
        /// </summary>
72
        public void Run()
73
        {
74
            string drawingNumber = document.DrawingNumber;
75
            string drawingName = document.DrawingName;
76
            try
77
            {
78
                _placement = new Placement();
79
                dataSource = _placement.PIDDataSource;
80

    
81
                CreateDocument(ref drawingNumber, ref drawingName);
82

    
83
                if (DocumentCoordinateCorrection())
84
                {
85
                    Log.Write("Start Modeling");
86
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
87
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
88
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
89

    
90
                    // Equipment Modeling
91
                    RunEquipmentModeling();
92

    
93
                    // Symbol Modeling
94
                    RunSymbolModeling();
95

    
96
                    // LineRun Line Modeling
97
                    RunLineModeling();
98

    
99
                    // Branch Line Modeling
100
                    RunBranchLineModeling();
101

    
102
                    // Clear Attribute
103
                    RunClearInconsistancy();
104

    
105
                    // EndBreak Modeling
106
                    RunEndBreakModeling();
107

    
108
                    // SpecBreak Modeling
109
                    RunSpecBreakModeling();
110

    
111
                    // Join
112
                    RunJoinRunForSameConnector();
113

    
114
                    //// LineNumber Modeling
115
                    //RunLineNumberModeling();
116

    
117
                    //// FlowMark Modeling
118
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Flow Mark Modeling");
119
                    //foreach (var item in document.LINES)
120
                    //    try
121
                    //    {
122
                    //        FlowMarkModeling(item);
123
                    //    }
124
                    //    catch (Exception ex)
125
                    //    {
126
                    //        Log.Write("Error in FlowMarkModeling");
127
                    //        Log.Write("UID : " + item.UID);
128
                    //        Log.Write(ex.Message);
129
                    //        Log.Write(ex.StackTrace);
130
                    //    }
131

    
132

    
133
                    //// Note Symbol Modeling
134
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Note Symbol Modeling");
135
                    //foreach (var item in document.SYMBOLS)
136
                    //    try
137
                    //    {
138
                    //        NoteSymbolModeling(item);
139
                    //    }
140
                    //    catch (Exception ex)
141
                    //    {
142
                    //        Log.Write("Error in NoteSymbolModeling");
143
                    //        Log.Write("UID : " + item.UID);
144
                    //        Log.Write(ex.Message);
145
                    //        Log.Write(ex.StackTrace);
146
                    //    }
147

    
148

    
149
                    //// Note Modeling
150
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
151
                    //foreach (var item in document.NOTES)
152
                    //    try
153
                    //    {
154
                    //        NoteModeling(item);
155
                    //    }
156
                    //    catch (Exception ex)
157
                    //    {
158
                    //        Log.Write("Error in NoteModeling");
159
                    //        Log.Write("UID : " + item.UID);
160
                    //        Log.Write(ex.Message);
161
                    //        Log.Write(ex.StackTrace);
162
                    //    }
163

    
164
                    //// Text Modeling
165
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
166
                    //foreach (var item in document.TEXTINFOS)
167
                    //    try
168
                    //    {
169
                    //        TextModeling(item);
170
                    //    }
171
                    //    catch (Exception ex)
172
                    //    {
173
                    //        Log.Write("Error in TextModeling");
174
                    //        Log.Write("UID : " + item.UID);
175
                    //        Log.Write(ex.Message);
176
                    //        Log.Write(ex.StackTrace);
177
                    //    }
178

    
179
                    //// Input LineNumber Attribute
180
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
181
                    //foreach (var item in document.LINENUMBERS)
182
                    //    try
183
                    //    {
184
                    //        InputLineNumberAttribute(item);
185
                    //    }
186
                    //    catch (Exception ex)
187
                    //    {
188
                    //        Log.Write("Error in InputLineNumberAttribute");
189
                    //        Log.Write("UID : " + item.UID);
190
                    //        Log.Write(ex.Message);
191
                    //        Log.Write(ex.StackTrace);
192
                    //    }
193

    
194
                    //// Input Symbol Attribute
195
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
196
                    //foreach (var item in document.SYMBOLS)
197
                    //    try
198
                    //    {
199
                    //        InputSymbolAttribute(item, item.ATTRIBUTES);
200
                    //    }
201
                    //    catch (Exception ex)
202
                    //    {
203
                    //        Log.Write("Error in InputSymbolAttribute");
204
                    //        Log.Write("UID : " + item.UID);
205
                    //        Log.Write(ex.Message);
206
                    //        Log.Write(ex.StackTrace);
207
                    //    }
208

    
209
                    //// Input SpecBreak Attribute
210
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
211
                    //foreach (var item in document.SpecBreaks)
212
                    //    try
213
                    //    {
214
                    //        InputSpecBreakAttribute(item);
215
                    //    }
216
                    //    catch (Exception ex)
217
                    //    {
218
                    //        Log.Write("Error in InputSpecBreakAttribute");
219
                    //        Log.Write("UID : " + item.UID);
220
                    //        Log.Write(ex.Message);
221
                    //        Log.Write(ex.StackTrace);
222
                    //    }
223

    
224
                    //// Label Symbol Modeling
225
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
226
                    //foreach (var item in document.SYMBOLS)
227
                    //    try
228
                    //    {
229
                    //        LabelSymbolModeling(item);
230
                    //    }
231
                    //    catch (Exception ex)
232
                    //    {
233
                    //        Log.Write("Error in LabelSymbolModeling");
234
                    //        Log.Write("UID : " + item.UID);
235
                    //        Log.Write(ex.Message);
236
                    //        Log.Write(ex.StackTrace);
237
                    //    }
238

    
239
                    //// LineRun Line Join
240
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
241
                    //foreach (LineNumber lineNumber in document.LINENUMBERS)
242
                    //    try
243
                    //    {
244
                    //        foreach (LineRun run in lineNumber.RUNS)
245
                    //            JoinRunLine(run);
246
                    //    }
247
                    //    catch (Exception ex)
248
                    //    {
249
                    //        Log.Write("Error in JoinRunLine");
250
                    //        Log.Write("UID : " + lineNumber.UID);
251
                    //        Log.Write(ex.Message);
252
                    //        Log.Write(ex.StackTrace);
253
                    //    }
254

    
255
                    //// TrimLineRun Line Join
256
                    //foreach (TrimLine trimLine in document.TRIMLINES)
257
                    //    try
258
                    //    {
259
                    //        foreach (LineRun run in trimLine.RUNS)
260
                    //            JoinRunLine(run);
261
                    //    }
262
                    //    catch (Exception ex)
263
                    //    {
264
                    //        Log.Write("Error in JoinRunLine");
265
                    //        Log.Write("UID : " + trimLine.UID);
266
                    //        Log.Write(ex.Message);
267
                    //        Log.Write(ex.StackTrace);
268
                    //    }
269
                }
270
            }
271
            catch (Exception ex)
272
            {
273
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
274
                SplashScreenManager.CloseForm(false);
275
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
276
            }
277
            finally
278
            {
279
                Log.Write("End Modeling");
280
                application.ActiveWindow.Fit();
281

    
282
                if (currentDrawing != null)
283
                    ReleaseCOMObjects(currentDrawing);
284

    
285
                if (radApp.ActiveDocument != null)
286
                {
287
                    radApp.ActiveDocument.Save();
288
                    ReleaseCOMObjects(newDrawing);
289
                }
290

    
291
                ReleaseCOMObjects(dataSource);
292
                ReleaseCOMObjects(_placement);
293

    
294
                Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document);
295
                if (SplashScreenManager.Default.IsSplashFormVisible)
296
                {
297
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
298
                    SplashScreenManager.CloseForm(false);
299
                    Log.Write("\r\n");
300
                }
301
            }
302
        }
303
        private void RunEquipmentModeling()
304
        {
305
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
306
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
307
            foreach (Equipment item in document.Equipments)
308
            {
309
                try
310
                {
311
                    EquipmentModeling(item);
312
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
313
                }
314
                catch (Exception ex)
315
                {
316
                    Log.Write("Error in EquipmentModeling");
317
                    Log.Write("UID : " + item.UID);
318
                    Log.Write(ex.Message);
319
                    Log.Write(ex.StackTrace);
320
                }
321
            }
322
        }
323
        private void RunSymbolModeling()
324
        {
325
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
326
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
327
            prioritySymbols = GetPrioritySymbol();
328
            foreach (var item in prioritySymbols)
329
            {
330
                try
331
                {
332
                    SymbolModelingBySymbol(item);
333
                }
334
                catch (Exception ex)
335
                {
336
                    Log.Write("Error in SymbolModelingByPriority");
337
                    Log.Write("UID : " + item.UID);
338
                    Log.Write(ex.Message);
339
                    Log.Write(ex.StackTrace);
340
                }
341
            }
342
        }
343
        private void RunLineModeling()
344
        {
345
            SetPriorityLine();
346
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
347
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
348
            foreach (var item in document.LINES)
349
            {
350
                try
351
                {
352
                    NewLineModeling(item);
353
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
354
                }
355
                catch (Exception ex)
356
                {
357
                    Log.Write("Error in NewLineModeling");
358
                    Log.Write("UID : " + item.UID);
359
                    Log.Write(ex.Message);
360
                    Log.Write(ex.StackTrace);
361
                }
362
            }
363
        }
364
        private void RunBranchLineModeling()
365
        {
366
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
367
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, NewBranchLines.Count);
368
            int branchCount = NewBranchLines.Count;
369
            while (NewBranchLines.Count > 0)
370
            {
371
                Line item = NewBranchLines[0];
372
                try
373
                {
374
                    SortBranchLines();
375
                    NewLineModeling(item, true);
376
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
377
                }
378
                catch (Exception ex)
379
                {
380
                    Log.Write("Error in NewLineModeling");
381
                    Log.Write("UID : " + item.UID);
382
                    Log.Write(ex.Message);
383
                    Log.Write(ex.StackTrace);
384
                }
385
            }
386
        }
387
        private void RunClearInconsistancy()
388
        {
389
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.LINES.Count);
390
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Attribute");
391
            SetSystemEditingCommand(false);
392

    
393
            bool loop = true;
394
            while (loop)
395
            {
396
                loop = false;
397
                LMAFilter filter = new LMAFilter();
398
                LMACriterion criterion = new LMACriterion();
399
                filter.ItemType = "Relationship";
400
                criterion.SourceAttributeName = "SP_DRAWINGID";
401
                criterion.Operator = "=";
402
                criterion.set_ValueAttribute(currentDrawing.Id);
403
                filter.get_Criteria().Add(criterion);
404

    
405
                LMRelationships relationships = new LMRelationships();
406
                relationships.Collect(dataSource, Filter: filter);
407

    
408
                foreach (LMRelationship relationship in relationships)
409
                {
410
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
411
                    {
412
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
413
                        {
414
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
415
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
416
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
417
                            if (modelItem1 != null)
418
                            {
419
                                string attrName = array[0];
420
                                if (attrName.Contains("PipingPoint"))
421
                                {
422
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
423
                                    int index = 1;
424
                                    while (modelItem1.Attributes["PipingPoint" + index + "." + originalAttr] != null)
425
                                    {
426
                                        LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
427
                                        if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
428
                                        {
429
                                            loop = true;
430
                                            attribute1.set_Value(DBNull.Value);
431
                                        }
432
                                        index++;
433
                                    }
434
                                }
435
                                else
436
                                {
437
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
438
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
439
                                    {
440
                                        loop = true;
441
                                        attribute1.set_Value(DBNull.Value);
442
                                    }
443
                                }
444
                                modelItem1.Commit();
445
                            }
446
                            if (modelItem2 != null)
447
                            {
448
                                string attrName = array[1];
449
                                if (attrName.Contains("PipingPoint"))
450
                                {
451
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
452
                                    int index = 1;
453
                                    while (modelItem2.Attributes["PipingPoint" + index + "." + originalAttr] != null)
454
                                    {
455
                                        LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
456
                                        if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
457
                                        {
458
                                            attribute2.set_Value(DBNull.Value);
459
                                            loop = true;
460
                                        }
461
                                        index++;
462
                                    }
463
                                }
464
                                else
465
                                {
466
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
467
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
468
                                    {
469
                                        attribute2.set_Value(DBNull.Value);
470
                                        loop = true;
471
                                    }
472
                                }
473
                                modelItem2.Commit();
474
                            }
475
                            if (modelItem1 != null)
476
                                ReleaseCOMObjects(modelItem1);
477
                            if (modelItem2 != null)
478
                                ReleaseCOMObjects(modelItem2);
479
                            inconsistency.Commit();
480
                        }
481
                    }
482
                    relationship.Commit();
483
                }
484
                ReleaseCOMObjects(filter);
485
                ReleaseCOMObjects(criterion);
486
                ReleaseCOMObjects(relationships);
487
            }
488

    
489
           
490

    
491
            //List<string> endClearModelItemID = new List<string>();
492
            //for (int i = 0; i < document.LINES.Count; i++)
493
            //{
494
            //    Line item = document.LINES[i];
495
            //    string modelItemID = item.SPPID.ModelItemId;
496
            //    if (!string.IsNullOrEmpty(modelItemID))
497
            //    {
498
            //        LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
499
            //        if (modelItem != null)
500
            //        {
501
            //            LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
502
            //            if (attribute != null)
503
            //                attribute.set_Value(DBNull.Value);
504

    
505
            //            modelItem.Commit();
506
            //            ReleaseCOMObjects(modelItem);
507
            //        }
508
            //    }
509
            //    if (!endClearModelItemID.Contains(modelItemID))
510
            //        endClearModelItemID.Add(modelItemID);
511
            //    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
512
            //}
513
            //for (int i = 0; i < document.SYMBOLS.Count; i++)
514
            //{
515
            //    Symbol item = document.SYMBOLS[i];
516
            //    string repID = item.SPPID.RepresentationId;
517
            //    string modelItemID = item.SPPID.ModelItemID;
518
            //    if (!string.IsNullOrEmpty(modelItemID))
519
            //    {
520
            //        LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
521
            //        if (modelItem != null)
522
            //        {
523
            //            LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
524
            //            if (attribute != null)
525
            //                attribute.set_Value(DBNull.Value);
526
            //            attribute = modelItem.Attributes["PipingPoint1.NominalDiameter"];
527
            //            if (attribute != null)
528
            //                attribute.set_Value(DBNull.Value);
529
            //            attribute = modelItem.Attributes["PipingPoint2.NominalDiameter"];
530
            //            if (attribute != null)
531
            //                attribute.set_Value(DBNull.Value);
532
            //            modelItem.Commit();
533

    
534
            //            modelItem.Commit();
535
            //            ReleaseCOMObjects(modelItem);
536
            //        }
537
            //    }
538
            //    if (!string.IsNullOrEmpty(repID))
539
            //    {
540
            //        LMSymbol symbol = dataSource.GetSymbol(repID);
541
            //        if (symbol != null)
542
            //        {
543
            //            foreach (LMConnector connector in symbol.Connect1Connectors)
544
            //            {
545
            //                if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
546
            //                {
547
            //                    endClearModelItemID.Add(connector.ModelItemID);
548
            //                    LMModelItem modelItem = connector.ModelItemObject;
549
            //                    if (modelItem != null)
550
            //                    {
551
            //                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
552
            //                        if (attribute != null)
553
            //                            attribute.set_Value(DBNull.Value);
554

    
555
            //                        modelItem.Commit();
556
            //                        ReleaseCOMObjects(modelItem);
557
            //                    }
558
            //                }
559
            //            }
560
            //            foreach (LMConnector connector in symbol.Connect2Connectors)
561
            //            {
562
            //                if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
563
            //                {
564
            //                    endClearModelItemID.Add(connector.ModelItemID);
565
            //                    LMModelItem modelItem = connector.ModelItemObject;
566
            //                    if (modelItem != null)
567
            //                    {
568
            //                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
569
            //                        if (attribute != null)
570
            //                            attribute.set_Value(DBNull.Value);
571

    
572
            //                        modelItem.Commit();
573
            //                        ReleaseCOMObjects(modelItem);
574
            //                    }
575
            //                }
576
            //            }
577
            //            ReleaseCOMObjects(symbol);
578
            //        }
579
            //    }
580
            //    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
581
            //}
582
            SetSystemEditingCommand(true);
583
        }
584
        private void RunEndBreakModeling()
585
        {
586
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
587
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
588
            foreach (var item in document.EndBreaks)
589
                try
590
                {
591
                    EndBreakModeling(item);
592
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
593
                    if (string.IsNullOrEmpty(item.SPPID.ModelItemID))
594
                        Log.Write("Fail modeling endbreak UID : " + item.UID);
595
                }
596
                catch (Exception ex)
597
                {
598
                    Log.Write("Error in EndBreakModeling");
599
                    Log.Write("UID : " + item.UID);
600
                    Log.Write(ex.Message);
601
                    Log.Write(ex.StackTrace);
602
                }
603
        }
604
        private void RunSpecBreakModeling()
605
        {
606
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
607
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
608
            foreach (var item in document.SpecBreaks)
609
                try
610
                {
611
                    SpecBreakModeling(item);
612
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
613
                    if (string.IsNullOrEmpty(item.SPPID.ModelItemID))
614
                        Log.Write("Fail modeling specbreak UID : " + item.UID);
615
                }
616
                catch (Exception ex)
617
                {
618
                    Log.Write("Error in SpecBreakModeling");
619
                    Log.Write("UID : " + item.UID);
620
                    Log.Write(ex.Message);
621
                    Log.Write(ex.StackTrace);
622
                }
623
        }
624
        private void RunJoinRunForSameConnector()
625
        {
626
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join");
627
            foreach (var line in document.LINES)
628
            {
629
                if (!SPPIDUtil.IsSegmentLine(document, line))
630
                {
631
                    foreach (var connector in line.CONNECTORS)
632
                    {
633
                        if (connector.ConnectedObject != null &&
634
                            connector.ConnectedObject.GetType() == typeof(Line) &&
635
                            !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line) &&
636
                            !SPPIDUtil.IsSegmentLine(document, connector.ConnectedObject as Line)) 
637
                        {
638
                            Line connLine = connector.ConnectedObject as Line;
639
                            if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId)
640
                                JoinPipeRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId);
641
                        }
642
                    }
643
                }
644
            }
645
        }
646

    
647
        private void RunLineNumberModeling()
648
        {
649
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling");
650
            foreach (var item in document.LINENUMBERS)
651
                try
652
                {
653
                    LineNumberModeling(item);
654
                }
655
                catch (Exception ex)
656
                {
657
                    Log.Write("Error in LineNumberModeling");
658
                    Log.Write("UID : " + item.UID);
659
                    Log.Write(ex.Message);
660
                    Log.Write(ex.StackTrace);
661
                }
662
        }
663

    
664
        /// <summary>
665
        /// 도면 생성 메서드
666
        /// </summary>
667
        private void CreateDocument(ref string drawingNumber, ref string drawingName)
668
        {
669
            Log.Write("------------------ Start create document ------------------");
670
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
671
            Log.Write("Drawing name : " + drawingName);
672
            Log.Write("Drawing number : " + drawingNumber);
673
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
674
            document.SPPID_DrawingNumber = drawingNumber;
675
            document.SPPID_DrawingName = drawingName;
676
            application.ActiveWindow.Fit();
677
            Thread.Sleep(1000);
678
            application.ActiveWindow.Zoom = 2000;
679
            Thread.Sleep(2000);
680

    
681
            //current LMDrawing 가져오기
682
            LMAFilter filter = new LMAFilter();
683
            LMACriterion criterion = new LMACriterion();
684
            filter.ItemType = "Drawing";
685
            criterion.SourceAttributeName = "Name";
686
            criterion.Operator = "=";
687
            criterion.set_ValueAttribute(drawingName);
688
            filter.get_Criteria().Add(criterion);
689

    
690
            LMDrawings drawings = new LMDrawings();
691
            drawings.Collect(dataSource, Filter: filter);
692

    
693
            currentDrawing = ((dynamic)drawings).Nth(1);
694
        }
695

    
696
        /// <summary>
697
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
698
        /// </summary>
699
        /// <param name="drawingName"></param>
700
        /// <param name="drawingNumber"></param>
701
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
702
        {
703
            LMDrawings drawings = new LMDrawings();
704
            drawings.Collect(dataSource);
705

    
706
            List<string> drawingNameList = new List<string>();
707
            List<string> drawingNumberList = new List<string>();
708

    
709
            foreach (LMDrawing item in drawings)
710
            {
711
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
712
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
713
            }
714

    
715
            int nameLength = drawingName.Length;
716
            while (drawingNameList.Contains(drawingName))
717
            {
718
                if (nameLength == drawingName.Length)
719
                    drawingName += "-1";
720
                else
721
                {
722
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
723
                    drawingName = drawingName.Substring(0, nameLength + 1);
724
                    drawingName += ++index;
725
                }
726
            }
727

    
728
            int numberLength = drawingNumber.Length;
729
            while (drawingNameList.Contains(drawingNumber))
730
            {
731
                if (numberLength == drawingNumber.Length)
732
                    drawingNumber += "-1";
733
                else
734
                {
735
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
736
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
737
                    drawingNumber += ++index;
738
                }
739
            }
740

    
741
            ReleaseCOMObjects(drawings);
742
        }
743

    
744
        /// <summary>
745
        /// 도면 크기 구하는 메서드
746
        /// </summary>
747
        /// <returns></returns>
748
        private bool DocumentCoordinateCorrection()
749
        {
750
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
751
            {
752
                Log.Write("Setting Drawing X, Drawing Y");
753
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
754
                Log.Write("Start coordinate correction");
755
                document.CoordinateCorrection();
756
                return true;
757
            }
758
            else
759
            {
760
                Log.Write("Need Drawing X, Y");
761
                return false;
762
            }
763
        }
764

    
765
        /// <summary>
766
        /// 심볼을 실제로 Modeling 메서드
767
        /// </summary>
768
        /// <param name="symbol"></param>
769
        /// <param name="targetSymbol"></param>
770
        /// <param name="prevSymbol"></param>
771
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
772
        {
773
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
774
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
775
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
776
                return;
777
            // 이미 모델링 됐을 경우
778
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
779
                return;
780

    
781
            LMSymbol _LMSymbol = null;
782

    
783
            string mappingPath = symbol.SPPID.MAPPINGNAME;
784
            double x = symbol.SPPID.ORIGINAL_X;
785
            double y = symbol.SPPID.ORIGINAL_Y;
786
            int mirror = 0;
787
            double angle = symbol.ANGLE;
788

    
789
            // OPC 일경우 180도 일때 Mirror
790
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
791
                mirror = 1;
792

    
793
            // Mirror 계산
794
            if (symbol.FLIP == 1)
795
            {
796
                mirror = 1;
797
                angle += Math.PI;
798
            }
799

    
800
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
801
            {
802
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
803
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
804
                if (connector != null)
805
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
806

    
807
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
808

    
809
                if (_LMSymbol != null && _TargetItem != null)
810
                {
811
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
812
                    LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
813

    
814
                    if (reModelingConnector != null)
815
                        ReModelingLMConnector(reModelingConnector);
816
                }
817

    
818
                ReleaseCOMObjects(_TargetItem);
819
            }
820
            else
821
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
822

    
823
            if (_LMSymbol != null)
824
            {
825
                _LMSymbol.Commit();
826
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
827
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
828
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
829

    
830
                foreach (var item in symbol.ChildSymbols)
831
                    CreateChildSymbol(item, _LMSymbol);
832

    
833
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
834
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
835

    
836
                double[] range = null;
837
                GetSPPIDSymbolRange(symbol, ref range);
838
                symbol.SPPID.SPPID_Min_X = range[0];
839
                symbol.SPPID.SPPID_Min_Y = range[1];
840
                symbol.SPPID.SPPID_Max_X = range[2];
841
                symbol.SPPID.SPPID_Max_Y = range[3];
842

    
843
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
844
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
845
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
846
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
847

    
848
                ReleaseCOMObjects(_LMSymbol);
849
            }
850
        }
851

    
852
        private void RemoveSymbol(Symbol symbol)
853
        {
854
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
855
            {
856
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
857
                if (_LMSymbol != null)
858
                {
859
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
860
                    ReleaseCOMObjects(_LMSymbol);
861
                }
862
            }
863

    
864
            symbol.SPPID.RepresentationId = string.Empty;
865
            symbol.SPPID.ModelItemID = string.Empty;
866
            symbol.SPPID.SPPID_X = double.NaN;
867
            symbol.SPPID.SPPID_Y = double.NaN;
868
            symbol.SPPID.SPPID_Min_X = double.NaN;
869
            symbol.SPPID.SPPID_Min_Y = double.NaN;
870
            symbol.SPPID.SPPID_Max_X = double.NaN;
871
            symbol.SPPID.SPPID_Max_Y = double.NaN;
872
        }
873

    
874
        private void RemoveSymbol(List<Symbol> symbols)
875
        {
876
            foreach (var symbol in symbols)
877
            {
878
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
879
                {
880
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
881
                    if (_LMSymbol != null)
882
                    {
883
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
884
                        ReleaseCOMObjects(_LMSymbol);
885
                    }
886
                }
887

    
888
                symbol.SPPID.RepresentationId = string.Empty;
889
                symbol.SPPID.ModelItemID = string.Empty;
890
                symbol.SPPID.SPPID_X = double.NaN;
891
                symbol.SPPID.SPPID_Y = double.NaN;
892
                symbol.SPPID.SPPID_Min_X = double.NaN;
893
                symbol.SPPID.SPPID_Min_Y = double.NaN;
894
                symbol.SPPID.SPPID_Max_X = double.NaN;
895
                symbol.SPPID.SPPID_Max_Y = double.NaN;
896
            }
897
        }
898

    
899
        /// <summary>
900
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
901
        /// </summary>
902
        /// <param name="targetConnector"></param>
903
        /// <param name="targetSymbol"></param>
904
        /// <param name="x"></param>
905
        /// <param name="y"></param>
906
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
907
        {
908
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
909

    
910
            double[] range = null;
911
            List<double[]> points = new List<double[]>();
912
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
913
            double x1 = range[0];
914
            double y1 = range[1];
915
            double x2 = range[2];
916
            double y2 = range[3];
917

    
918
            // Origin 기준 Connector의 위치차이
919
            double sceneX = 0;
920
            double sceneY = 0;
921
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
922
            double originX = 0;
923
            double originY = 0;
924
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
925
            double gapX = originX - sceneX;
926
            double gapY = originY - sceneY;
927

    
928
            // SPPID Symbol과 ID2 심볼의 크기 차이
929
            double sizeWidth = 0;
930
            double sizeHeight = 0;
931
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
932
            if (sizeWidth == 0 || sizeHeight == 0)
933
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
934

    
935
            double percentX = (x2 - x1) / sizeWidth;
936
            double percentY = (y2 - y1) / sizeHeight;
937

    
938
            double SPPIDgapX = gapX * percentX;
939
            double SPPIDgapY = gapY * percentY;
940

    
941
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
942
            double distance = double.MaxValue;
943
            double[] resultPoint;
944
            foreach (var point in points)
945
            {
946
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
947
                if (distance > result)
948
                {
949
                    distance = result;
950
                    resultPoint = point;
951
                    x = point[0];
952
                    y = point[1];
953
                }
954
            }
955

    
956
            ReleaseCOMObjects(_TargetItem);
957
        }
958

    
959
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
960
        {
961
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
962
            if (index == 0)
963
            {
964
                x = targetLine.SPPID.START_X;
965
                y = targetLine.SPPID.START_Y;
966
            }
967
            else
968
            {
969
                x = targetLine.SPPID.END_X;
970
                y = targetLine.SPPID.END_Y;
971
            }
972
        }
973

    
974
        /// <summary>
975
        /// SPPID Symbol의 Range를 구한다.
976
        /// </summary>
977
        /// <param name="symbol"></param>
978
        /// <param name="range"></param>
979
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
980
        {
981
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
982
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
983
            double x1 = 0;
984
            double y1 = 0;
985
            double x2 = 0;
986
            double y2 = 0;
987
            symbol2d.Range(out x1, out y1, out x2, out y2);
988
            range = new double[] { x1, y1, x2, y2 };
989

    
990
            for (int i = 1; i < int.MaxValue; i++)
991
            {
992
                double connX = 0;
993
                double connY = 0;
994
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
995
                    points.Add(new double[] { connX, connY });
996
                else
997
                    break;
998
            }
999

    
1000
            foreach (var childSymbol in symbol.ChildSymbols)
1001
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1002

    
1003
            ReleaseCOMObjects(_TargetItem);
1004
        }
1005

    
1006
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1007
        {
1008
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1009
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1010
            double x1 = 0;
1011
            double y1 = 0;
1012
            double x2 = 0;
1013
            double y2 = 0;
1014
            symbol2d.Range(out x1, out y1, out x2, out y2);
1015
            range = new double[] { x1, y1, x2, y2 };
1016

    
1017
            foreach (var childSymbol in symbol.ChildSymbols)
1018
                GetSPPIDChildSymbolRange(childSymbol, ref range);
1019

    
1020
            ReleaseCOMObjects(_TargetItem);
1021
        }
1022

    
1023
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1024
        {
1025
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1026
            foreach (var symbol in symbols)
1027
            {
1028
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1029
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1030
                double x1 = 0;
1031
                double y1 = 0;
1032
                double x2 = 0;
1033
                double y2 = 0;
1034
                symbol2d.Range(out x1, out y1, out x2, out y2);
1035

    
1036
                tempRange[0] = Math.Min(tempRange[0], x1);
1037
                tempRange[1] = Math.Min(tempRange[1], y1);
1038
                tempRange[2] = Math.Max(tempRange[2], x2);
1039
                tempRange[3] = Math.Max(tempRange[3], y2);
1040

    
1041
                foreach (var childSymbol in symbol.ChildSymbols)
1042
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1043

    
1044
                ReleaseCOMObjects(_TargetItem);
1045
            }
1046

    
1047
            range = tempRange;
1048
        }
1049

    
1050
        /// <summary>
1051
        /// Child Modeling 된 Symbol의 Range를 구한다.
1052
        /// </summary>
1053
        /// <param name="childSymbol"></param>
1054
        /// <param name="range"></param>
1055
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1056
        {
1057
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1058
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1059
            double x1 = 0;
1060
            double y1 = 0;
1061
            double x2 = 0;
1062
            double y2 = 0;
1063
            symbol2d.Range(out x1, out y1, out x2, out y2);
1064
            range[0] = Math.Min(range[0], x1);
1065
            range[1] = Math.Min(range[1], y1);
1066
            range[2] = Math.Max(range[2], x2);
1067
            range[3] = Math.Max(range[3], y2);
1068

    
1069
            for (int i = 1; i < int.MaxValue; i++)
1070
            {
1071
                double connX = 0;
1072
                double connY = 0;
1073
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1074
                    points.Add(new double[] { connX, connY });
1075
                else
1076
                    break;
1077
            }
1078

    
1079
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1080
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1081

    
1082
            ReleaseCOMObjects(_ChildSymbol);
1083
        }
1084

    
1085
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1086
        {
1087
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1088
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1089
            double x1 = 0;
1090
            double y1 = 0;
1091
            double x2 = 0;
1092
            double y2 = 0;
1093
            symbol2d.Range(out x1, out y1, out x2, out y2);
1094
            range[0] = Math.Min(range[0], x1);
1095
            range[1] = Math.Min(range[1], y1);
1096
            range[2] = Math.Max(range[2], x2);
1097
            range[3] = Math.Max(range[3], y2);
1098

    
1099
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1100
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1101

    
1102
            ReleaseCOMObjects(_ChildSymbol);
1103
        }
1104

    
1105
        /// <summary>
1106
        /// Label Symbol Modeling
1107
        /// </summary>
1108
        /// <param name="symbol"></param>
1109
        private void LabelSymbolModeling(Symbol symbol)
1110
        {
1111
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1112
            {
1113
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1114
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1115
                    return;
1116
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1117

    
1118
                string symbolUID = itemAttribute.VALUE;
1119
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1120
                if (targetItem != null &&
1121
                    (targetItem.GetType() == typeof(Symbol) ||
1122
                    targetItem.GetType() == typeof(Equipment)))
1123
                {
1124
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1125
                    string sRep = null;
1126
                    if (targetItem.GetType() == typeof(Symbol))
1127
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1128
                    else if (targetItem.GetType() == typeof(Equipment))
1129
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1130
                    if (!string.IsNullOrEmpty(sRep))
1131
                    {
1132
                        // LEADER Line 검사
1133
                        bool leaderLine = false;
1134
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1135
                        if (symbolMapping != null)
1136
                            leaderLine = symbolMapping.LEADERLINE;
1137

    
1138
                        // Target Symbol Item 가져오고 Label Modeling
1139
                        LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
1140
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1141

    
1142
                        //Leader 선 센터로
1143
                        if (_LMLabelPresist != null)
1144
                        {
1145
                            // Target Item에 Label의 Attribute Input
1146
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1147

    
1148
                            string OID = _LMLabelPresist.get_GraphicOID();
1149
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1150
                            if (dependency != null)
1151
                            {
1152
                                bool result = false;
1153
                                foreach (var attributes in dependency.AttributeSets)
1154
                                {
1155
                                    foreach (var attribute in attributes)
1156
                                    {
1157
                                        string name = attribute.Name;
1158
                                        string value = attribute.GetValue().ToString();
1159
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1160
                                        {
1161
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1162
                                            {
1163
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1164
                                                {
1165
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1166
                                                    double prevX = _TargetItem.get_XCoordinate();
1167
                                                    double prevY = _TargetItem.get_YCoordinate();
1168
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1169
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1170
                                                    result = true;
1171
                                                    break;
1172
                                                }
1173
                                            }
1174
                                        }
1175

    
1176
                                        if (result)
1177
                                            break;
1178
                                    }
1179

    
1180
                                    if (result)
1181
                                        break;
1182
                                }
1183
                            }
1184

    
1185
                            _LMLabelPresist.Commit();
1186
                            ReleaseCOMObjects(_LMLabelPresist);
1187
                        }
1188

    
1189
                        ReleaseCOMObjects(_TargetItem);
1190
                    }
1191
                }
1192
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1193
                {
1194
                    Line targetLine = targetItem as Line;
1195
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1196
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1197
                    if (connectedLMConnector != null)
1198
                    {
1199
                        // LEADER Line 검사
1200
                        bool leaderLine = false;
1201
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1202
                        if (symbolMapping != null)
1203
                            leaderLine = symbolMapping.LEADERLINE;
1204

    
1205
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1206
                        if (_LMLabelPresist != null)
1207
                        {
1208
                            _LMLabelPresist.Commit();
1209
                            ReleaseCOMObjects(_LMLabelPresist);
1210
                        }
1211
                        ReleaseCOMObjects(connectedLMConnector);
1212
                    }
1213

    
1214
                    foreach (var item in connectorVertices)
1215
                        if (item.Key != null)
1216
                            ReleaseCOMObjects(item.Key);
1217
                }
1218
            }
1219
        }
1220

    
1221
        /// <summary>
1222
        /// Equipment를 실제로 Modeling 메서드
1223
        /// </summary>
1224
        /// <param name="equipment"></param>
1225
        private void EquipmentModeling(Equipment equipment)
1226
        {
1227
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1228
                return;
1229

    
1230
            LMSymbol _LMSymbol = null;
1231
            LMSymbol targetItem = null;
1232
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1233
            double x = equipment.SPPID.ORIGINAL_X;
1234
            double y = equipment.SPPID.ORIGINAL_Y;
1235
            int mirror = 0;
1236
            double angle = equipment.ANGLE;
1237

    
1238
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1239

    
1240
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1241
            if (connector != null)
1242
            {
1243
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1244
                if (connEquipment != null)
1245
                {
1246
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1247
                        EquipmentModeling(connEquipment);
1248

    
1249
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1250
                    {
1251
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1252
                        if (targetItem != null)
1253
                        {
1254
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1255
                        }
1256
                        else
1257
                        {
1258
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1259
                        }
1260
                    }
1261
                    else
1262
                    {
1263
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1264
                    }
1265
                }
1266
                else
1267
                {
1268
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1269
                }
1270
            }
1271
            else
1272
            {
1273
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1274
            }
1275

    
1276
            if (_LMSymbol != null)
1277
            {
1278
                _LMSymbol.Commit();
1279
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1280
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID();
1281
                ReleaseCOMObjects(_LMSymbol);
1282
            }
1283

    
1284
            if (targetItem != null)
1285
            {
1286
                ReleaseCOMObjects(targetItem);
1287
            }
1288

    
1289
            ReleaseCOMObjects(_LMSymbol);
1290
        }
1291

    
1292
        /// <summary>
1293
        /// 첫 진입점
1294
        /// </summary>
1295
        /// <param name="symbol"></param>
1296
        private void SymbolModelingBySymbol(Symbol symbol)
1297
        {
1298
            SymbolModeling(symbol, null);
1299
            List<object> endObjects = new List<object>();
1300
            endObjects.Add(symbol);
1301

    
1302
            foreach (var connector in symbol.CONNECTORS)
1303
            {
1304
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1305
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1306
                {
1307
                    endObjects.Add(connItem);
1308
                    if (connItem.GetType() == typeof(Symbol))
1309
                    {
1310
                        Symbol connSymbol = connItem as Symbol;
1311
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1312
                        {
1313
                            SymbolModeling(connSymbol, symbol);
1314
                        }
1315
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1316
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1317
                    }
1318
                    else if (connItem.GetType() == typeof(Line))
1319
                    {
1320
                        Line connLine = connItem as Line;
1321
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1322
                    }
1323
                }
1324
            }
1325
        }
1326

    
1327
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1328
        {
1329
            foreach (var connector in symbol.CONNECTORS)
1330
            {
1331
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1332
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1333
                {
1334
                    if (!endObjects.Contains(connItem))
1335
                    {
1336
                        endObjects.Add(connItem);
1337
                        if (connItem.GetType() == typeof(Symbol))
1338
                        {
1339
                            Symbol connSymbol = connItem as Symbol;
1340
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1341
                            {
1342
                                SymbolModeling(connSymbol, symbol);
1343
                            }
1344
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1345
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1346
                        }
1347
                        else if (connItem.GetType() == typeof(Line))
1348
                        {
1349
                            Line connLine = connItem as Line;
1350
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1351
                        }
1352
                    }
1353
                }
1354
            }
1355
        }
1356

    
1357
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1358
        {
1359
            foreach (var connector in line.CONNECTORS)
1360
            {
1361
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1362
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1363
                {
1364
                    if (!endObjects.Contains(connItem))
1365
                    {
1366
                        endObjects.Add(connItem);
1367
                        if (connItem.GetType() == typeof(Symbol))
1368
                        {
1369
                            Symbol connSymbol = connItem as Symbol;
1370
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1371
                            {
1372
                                List<Symbol> group = new List<Symbol>();
1373
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1374
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1375
                                List<Symbol> endModelingGroup = new List<Symbol>();
1376
                                if (priority != null)
1377
                                {
1378
                                    SymbolGroupModeling(priority, group);
1379

    
1380
                                    // Range 겹치는지 확인해야함
1381
                                    double[] prevRange = null;
1382
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1383
                                    double[] groupRange = null;
1384
                                    GetSPPIDSymbolRange(group, ref groupRange);
1385

    
1386
                                    double distanceX = 0;
1387
                                    double distanceY = 0;
1388
                                    bool overlapX = false;
1389
                                    bool overlapY = false;
1390
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1391
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1392
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1393
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1394
                                    {
1395
                                        RemoveSymbol(group);
1396
                                        foreach (var _temp in group)
1397
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1398

    
1399
                                        SymbolGroupModeling(priority, group);
1400
                                    }
1401
                                }
1402
                                else
1403
                                {
1404
                                    SymbolModeling(connSymbol, null);
1405
                                    // Range 겹치는지 확인해야함
1406
                                    double[] prevRange = null;
1407
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1408
                                    double[] connRange = null;
1409
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1410

    
1411
                                    double distanceX = 0;
1412
                                    double distanceY = 0;
1413
                                    bool overlapX = false;
1414
                                    bool overlapY = false;
1415
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1416
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1417
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1418
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1419
                                    {
1420
                                        RemoveSymbol(connSymbol);
1421
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1422

    
1423
                                        SymbolModeling(connSymbol, null);
1424
                                    }
1425
                                }
1426
                            }
1427
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1428
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1429
                        }
1430
                        else if (connItem.GetType() == typeof(Line))
1431
                        {
1432
                            Line connLine = connItem as Line;
1433
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1434
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1435
                        }
1436
                    }
1437
                }
1438
            }
1439
        }
1440

    
1441
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1442
        {
1443
            List<Symbol> endModelingGroup = new List<Symbol>();
1444
            SymbolModeling(firstSymbol, null);
1445
            endModelingGroup.Add(firstSymbol);
1446
            while (endModelingGroup.Count != group.Count)
1447
            {
1448
                foreach (var _symbol in group)
1449
                {
1450
                    if (!endModelingGroup.Contains(_symbol))
1451
                    {
1452
                        foreach (var _connector in _symbol.CONNECTORS)
1453
                        {
1454
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
1455
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
1456
                            {
1457
                                SymbolModeling(_symbol, _connSymbol);
1458
                                endModelingGroup.Add(_symbol);
1459
                                break;
1460
                            }
1461
                        }
1462
                    }
1463
                }
1464
            }
1465
        }
1466

    
1467
        /// <summary>
1468
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
1469
        /// </summary>
1470
        /// <param name="childSymbol"></param>
1471
        /// <param name="parentSymbol"></param>
1472
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
1473
        {
1474
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
1475
            double x1 = 0;
1476
            double x2 = 0;
1477
            double y1 = 0;
1478
            double y2 = 0;
1479
            symbol2d.Range(out x1, out y1, out x2, out y2);
1480

    
1481
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1482
            if (_LMSymbol != null)
1483
            {
1484
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1485
                foreach (var item in childSymbol.ChildSymbols)
1486
                    CreateChildSymbol(item, _LMSymbol);
1487
            }
1488

    
1489

    
1490
            ReleaseCOMObjects(_LMSymbol);
1491
        }
1492

    
1493
        private void NewLineModeling(Line line, bool isBranchModeling = false, Tuple<LMConnector, bool, bool> reModelingInfo = null)
1494
        {
1495
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (NewBranchLines.Contains(line) && !isBranchModeling))
1496
                return;
1497

    
1498
            List<Line> group = new List<Line>();
1499
            GetConnectedLineGroup(line, group);
1500
            LineCoordinateCorrection(group);
1501

    
1502
            foreach (var groupLine in group)
1503
            {
1504
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1505
                {
1506
                    NewBranchLines.Add(groupLine);
1507
                    continue;
1508
                }
1509

    
1510
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
1511
                LMSymbol _LMSymbolStart = null;
1512
                LMSymbol _LMSymbolEnd = null;
1513
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1514
                foreach (var connector in groupLine.CONNECTORS)
1515
                {
1516
                    double x = 0;
1517
                    double y = 0;
1518
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
1519
                    if (connector.ConnectedObject == null)
1520
                    {
1521
                        placeRunInputs.AddPoint(x, y);
1522
                    }
1523
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
1524
                    {
1525
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
1526
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1527
                        {
1528
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
1529
                            placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y);
1530
                        }
1531
                        else
1532
                        {
1533
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
1534
                            placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y);
1535
                        }
1536
                    }
1537
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
1538
                    {
1539
                        Line targetLine = connector.ConnectedObject as Line;
1540
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
1541
                        {
1542
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
1543
                            placeRunInputs.AddConnectorTarget(targetConnector, x, y);
1544
                            ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1545
                        }
1546
                        else
1547
                        {
1548
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1549
                            {
1550
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1551
                                    placeRunInputs.AddPoint(x, -0.1);
1552
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1553
                                    placeRunInputs.AddPoint(-0.1, y);
1554
                                else
1555
                                    placeRunInputs.AddPoint(x, -0.1);
1556
                            }
1557

    
1558
                            placeRunInputs.AddPoint(x, y);
1559

    
1560
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1561
                            {
1562
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1563
                                    placeRunInputs.AddPoint(x, -0.1);
1564
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1565
                                    placeRunInputs.AddPoint(-0.1, y);
1566
                                else
1567
                                    placeRunInputs.AddPoint(x, -0.1);
1568
                            }
1569
                        }
1570
                    }
1571
                }
1572

    
1573
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1574
                if (_lMConnector != null)
1575
                {
1576
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1577
                    bool bRemodelingStart = false;
1578
                    if (_LMSymbolStart != null)
1579
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1580
                    bool bRemodelingEnd = false;
1581
                    if (_LMSymbolEnd != null)
1582
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1583

    
1584
                    if (bRemodelingStart || bRemodelingEnd)
1585
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1586
                    
1587
                    ReleaseCOMObjects(_lMConnector);
1588
                }
1589

    
1590
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1591
                x.ConnectedObject != null &&
1592
                x.ConnectedObject.GetType() == typeof(Line) &&
1593
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1594
                .Select(x => x.ConnectedObject)
1595
                .ToList();
1596

    
1597
                foreach (var item in removeLines)
1598
                    RemoveLineForModeling(item as Line);
1599

    
1600
                if (_LMAItem != null)
1601
                    ReleaseCOMObjects(_LMAItem);
1602
                if (placeRunInputs != null)
1603
                    ReleaseCOMObjects(placeRunInputs);
1604
                if (_LMSymbolStart != null)
1605
                    ReleaseCOMObjects(_LMSymbolStart);
1606
                if (_LMSymbolEnd != null)
1607
                    ReleaseCOMObjects(_LMSymbolEnd);
1608

    
1609
                if (isBranchModeling && NewBranchLines.Contains(groupLine))
1610
                    NewBranchLines.Remove(groupLine);
1611
            }
1612
        }
1613

    
1614
        private void RemoveLineForModeling(Line line)
1615
        {
1616
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1617
            if (modelItem != null)
1618
            {
1619
                foreach (LMRepresentation rep in modelItem.Representations)
1620
                {
1621
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1622
                    {
1623
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1624
                        dynamic OID = rep.get_GraphicOID();
1625
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1626
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1627
                        int verticesCount = lineStringGeometry.VertexCount;
1628
                        double[] vertices = null;
1629
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1630
                        for (int i = 0; i < verticesCount; i++)
1631
                        {
1632
                            double x = 0;
1633
                            double y = 0;
1634
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1635
                            if (verticesCount == 2 && x < 0 || y < 0)
1636
                                _placement.PIDRemovePlacement(rep);
1637
                        }
1638
                        ReleaseCOMObjects(_LMConnector);
1639
                    }
1640
                }
1641

    
1642
                ReleaseCOMObjects(modelItem);
1643
            }
1644
        }
1645

    
1646
        private void GetConnectedLineGroup(Line line, List<Line> group)
1647
        {
1648
            if (!group.Contains(line))
1649
                group.Add(line);
1650
            foreach (var connector in line.CONNECTORS)
1651
            {
1652
                if (connector.ConnectedObject != null &&
1653
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1654
                    !group.Contains(connector.ConnectedObject) &&
1655
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
1656
                {
1657
                    Line connLine = connector.ConnectedObject as Line;
1658
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
1659
                        GetConnectedLineGroup(connLine, group);
1660
                }
1661
            }
1662
        }
1663

    
1664
        private void LineCoordinateCorrection(List<Line> group)
1665
        {
1666
            // 순서대로 전 Item 기준 정렬
1667
            LineCoordinateCorrectionByStart(group);
1668

    
1669
            // 역으로 심볼이 있을 경우 좌표 보정
1670
            LineCoordinateCorrectionForLastLine(group);
1671
        }
1672

    
1673
        private void LineCoordinateCorrectionByStart(List<Line> group)
1674
        {
1675
            for (int i = 0; i < group.Count; i++)
1676
            {
1677
                Line line = group[i];
1678
                if (i == 0)
1679
                {
1680
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1681
                    if (symbolConnector != null)
1682
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
1683
                }
1684
                else if (i != 0)
1685
                {
1686
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
1687
                }
1688
            }
1689
        }
1690

    
1691
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
1692
        {
1693
            Line checkLine = group[group.Count - 1];
1694
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1695
            if (lastSymbolConnector != null)
1696
            {
1697
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
1698
                for (int i = group.Count - 2; i >= 0; i--)
1699
                {
1700
                    Line line = group[i + 1];
1701
                    Line prevLine = group[i];
1702

    
1703
                    // 같으면 보정
1704
                    if (line.SlopeType == prevLine.SlopeType)
1705
                        LineCoordinateCorrectionByConnItem(prevLine, line);
1706
                    else
1707
                    {
1708
                        if (line.SlopeType == SlopeType.HORIZONTAL)
1709
                        {
1710
                            double prevX = 0;
1711
                            double prevY = 0;
1712
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1713
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
1714

    
1715
                            double x = 0;
1716
                            double y = 0;
1717
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1718
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
1719
                        }
1720
                        else if (line.SlopeType == SlopeType.VERTICAL)
1721
                        {
1722
                            double prevX = 0;
1723
                            double prevY = 0;
1724
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1725
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
1726

    
1727
                            double x = 0;
1728
                            double y = 0;
1729
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1730
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
1731
                        }
1732
                        break;
1733
                    }
1734
                }
1735
            }
1736
        }
1737

    
1738
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
1739
        {
1740
            double x = 0;
1741
            double y = 0;
1742
            if (connItem.GetType() == typeof(Symbol))
1743
            {
1744
                Symbol targetSymbol = connItem as Symbol;
1745
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
1746
                if (targetConnector != null)
1747
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
1748
                else
1749
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
1750
            }
1751
            else if (connItem.GetType() == typeof(Line))
1752
            {
1753
                Line targetLine = connItem as Line;
1754
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
1755
            }
1756

    
1757
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
1758
        }
1759

    
1760
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
1761
        {
1762
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1763
            int index = line.CONNECTORS.IndexOf(connector);
1764
            if (index == 0)
1765
            {
1766
                line.SPPID.START_X = x;
1767
                line.SPPID.START_Y = y;
1768
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1769
                    line.SPPID.END_Y = y;
1770
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1771
                    line.SPPID.END_X = x;
1772
            }
1773
            else
1774
            {
1775
                line.SPPID.END_X = x;
1776
                line.SPPID.END_Y = y;
1777
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1778
                    line.SPPID.START_Y = y;
1779
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1780
                    line.SPPID.START_X = x;
1781
            }
1782
        }
1783

    
1784
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
1785
        {
1786
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1787
            int index = line.CONNECTORS.IndexOf(connector);
1788
            if (index == 0)
1789
            {
1790
                line.SPPID.START_X = x;
1791
                if (line.SlopeType == SlopeType.VERTICAL)
1792
                    line.SPPID.END_X = x;
1793
            }
1794
            else
1795
            {
1796
                line.SPPID.END_X = x;
1797
                if (line.SlopeType == SlopeType.VERTICAL)
1798
                    line.SPPID.START_X = x;
1799
            }
1800
        }
1801

    
1802
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
1803
        {
1804
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1805
            int index = line.CONNECTORS.IndexOf(connector);
1806
            if (index == 0)
1807
            {
1808
                line.SPPID.START_Y = y;
1809
                if (line.SlopeType == SlopeType.HORIZONTAL)
1810
                    line.SPPID.END_Y = y;
1811
            }
1812
            else
1813
            {
1814
                line.SPPID.END_Y = y;
1815
                if (line.SlopeType == SlopeType.HORIZONTAL)
1816
                    line.SPPID.START_Y = y;
1817
            }
1818
        }
1819

    
1820
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1821
        {
1822
            if (symbol != null)
1823
            {
1824
                string repID = symbol.AsLMRepresentation().Id;
1825
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1826
                string lineUID = line.UID;
1827

    
1828
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1829
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1830
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1831

    
1832
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
1833
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1834
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1835

    
1836
                if (startSpecBreak != null || startEndBreak != null)
1837
                    result = true;
1838
            }
1839
        }
1840

    
1841
        /// <summary>
1842
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1843
        /// </summary>
1844
        /// <param name="lines"></param>
1845
        /// <param name="prevLMConnector"></param>
1846
        /// <param name="startSymbol"></param>
1847
        /// <param name="endSymbol"></param>
1848
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1849
        {
1850
            string symbolPath = string.Empty;
1851
            #region get symbol path
1852
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1853
            foreach (LMRepresentation rep in modelItem.Representations)
1854
            {
1855
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1856
                {
1857
                    symbolPath = rep.get_FileName();
1858
                    break;
1859
                }
1860
            }
1861
            #endregion
1862
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1863
            LMConnector newConnector = null;
1864
            dynamic OID = prevLMConnector.get_GraphicOID();
1865
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1866
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1867
            int verticesCount = lineStringGeometry.VertexCount;
1868
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1869

    
1870
            List<double[]> vertices = new List<double[]>();
1871
            for (int i = 1; i <= verticesCount; i++)
1872
            {
1873
                double x = 0;
1874
                double y = 0;
1875
                lineStringGeometry.GetVertex(i, ref x, ref y);
1876
                vertices.Add(new double[] { x, y });
1877
            }
1878

    
1879
            for (int i = 0; i < vertices.Count; i++)
1880
            {
1881
                double[] points = vertices[i];
1882
                // 시작 심볼이 있고 첫번째 좌표일 때
1883
                if (startSymbol != null && i == 0)
1884
                {
1885
                    if (bStart)
1886
                    {
1887
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1888
                        if (slopeType == SlopeType.HORIZONTAL)
1889
                            placeRunInputs.AddPoint(points[0], -0.1);
1890
                        else if (slopeType == SlopeType.VERTICAL)
1891
                            placeRunInputs.AddPoint(-0.1, points[1]);
1892
                        else
1893
                            placeRunInputs.AddPoint(points[0], -0.1);
1894

    
1895
                        placeRunInputs.AddPoint(points[0], points[1]);
1896
                    }
1897
                    else
1898
                    {
1899
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1]);
1900
                    }
1901
                }
1902
                // 마지막 심볼이 있고 마지막 좌표일 때
1903
                else if (endSymbol != null && i == vertices.Count - 1)
1904
                {
1905
                    if (bEnd)
1906
                    {
1907
                        placeRunInputs.AddPoint(points[0], points[1]);
1908

    
1909
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1910
                        if (slopeType == SlopeType.HORIZONTAL)
1911
                            placeRunInputs.AddPoint(points[0], -0.1);
1912
                        else if (slopeType == SlopeType.VERTICAL)
1913
                            placeRunInputs.AddPoint(-0.1, points[1]);
1914
                        else
1915
                            placeRunInputs.AddPoint(points[0], -0.1);
1916
                    }
1917
                    else
1918
                    {
1919
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1]);
1920
                    }
1921
                }
1922
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1923
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1924
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1925
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1926
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1927
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1928
                else
1929
                    placeRunInputs.AddPoint(points[0], points[1]);
1930
            }
1931

    
1932
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1933
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1934

    
1935
            ReleaseCOMObjects(placeRunInputs);
1936
            ReleaseCOMObjects(_LMAItem);
1937
            ReleaseCOMObjects(modelItem);
1938

    
1939
            if (newConnector != null)
1940
            {
1941
                if (startSymbol != null && bStart)
1942
                {
1943
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1944
                    placeRunInputs = new PlaceRunInputs();
1945
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1946
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1947
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1948
                    if (_LMConnector != null)
1949
                    {
1950
                        RemoveConnectorForReModelingLine(newConnector);
1951
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1952
                        ReleaseCOMObjects(_LMConnector);
1953
                    }
1954
                    ReleaseCOMObjects(placeRunInputs);
1955
                    ReleaseCOMObjects(_LMAItem);
1956
                }
1957

    
1958
                if (endSymbol != null && bEnd)
1959
                {
1960
                    if (startSymbol != null)
1961
                    {
1962
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1963
                        newConnector = dicVertices.First().Key;
1964
                    }
1965

    
1966
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1967
                    placeRunInputs = new PlaceRunInputs();
1968
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1969
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1970
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1971
                    if (_LMConnector != null)
1972
                    {
1973
                        RemoveConnectorForReModelingLine(newConnector);
1974
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1975
                        ReleaseCOMObjects(_LMConnector);
1976
                    }
1977
                    ReleaseCOMObjects(placeRunInputs);
1978
                    ReleaseCOMObjects(_LMAItem);
1979
                }
1980

    
1981
                line.SPPID.ModelItemId = newConnector.ModelItemID;
1982
                ReleaseCOMObjects(newConnector);
1983
            }
1984

    
1985
            ReleaseCOMObjects(modelItem);
1986
        }
1987

    
1988
        /// <summary>
1989
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
1990
        /// </summary>
1991
        /// <param name="connector"></param>
1992
        private void RemoveConnectorForReModelingLine(LMConnector connector)
1993
        {
1994
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
1995
            foreach (var item in dicVertices)
1996
            {
1997
                if (item.Value.Count == 2)
1998
                {
1999
                    bool result = false;
2000
                    foreach (var point in item.Value)
2001
                    {
2002
                        if (point[0] < 0 || point[1] < 0)
2003
                        {
2004
                            result = true;
2005
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2006
                            break;
2007
                        }
2008
                    }
2009

    
2010
                    if (result)
2011
                        break;
2012
                }
2013
            }
2014
            foreach (var item in dicVertices)
2015
                ReleaseCOMObjects(item.Key);
2016
        }
2017

    
2018
        /// <summary>
2019
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2020
        /// </summary>
2021
        /// <param name="symbol"></param>
2022
        /// <param name="line"></param>
2023
        /// <returns></returns>
2024
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2025
        {
2026
            LMSymbol _LMSymbol = null;
2027
            foreach (var connector in symbol.CONNECTORS)
2028
            {
2029
                if (connector.CONNECTEDITEM == line.UID)
2030
                {
2031
                    if (connector.Index == 0)
2032
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2033
                    else
2034
                    {
2035
                        ChildSymbol child = null;
2036
                        foreach (var childSymbol in symbol.ChildSymbols)
2037
                        {
2038
                            if (childSymbol.Connectors.Contains(connector))
2039
                                child = childSymbol;
2040
                            else
2041
                                child = GetChildSymbolByConnector(childSymbol, connector);
2042

    
2043
                            if (child != null)
2044
                                break;
2045
                        }
2046

    
2047
                        if (child != null)
2048
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2049
                    }
2050

    
2051
                    break;
2052
                }
2053
            }
2054

    
2055
            return _LMSymbol;
2056
        }
2057

    
2058
        /// <summary>
2059
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2060
        /// </summary>
2061
        /// <param name="item"></param>
2062
        /// <param name="connector"></param>
2063
        /// <returns></returns>
2064
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2065
        {
2066
            foreach (var childSymbol in item.ChildSymbols)
2067
            {
2068
                if (childSymbol.Connectors.Contains(connector))
2069
                    return childSymbol;
2070
                else
2071
                    return GetChildSymbolByConnector(childSymbol, connector);
2072
            }
2073

    
2074
            return null;
2075
        }
2076

    
2077
        /// <summary>
2078
        /// EndBreak 모델링 메서드
2079
        /// </summary>
2080
        /// <param name="endBreak"></param>
2081
        private void EndBreakModeling(EndBreak endBreak)
2082
        {
2083
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2084
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2085
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2086

    
2087
            if (targetLMConnector != null)
2088
            {
2089
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2090
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2091
                if (_LmLabelPersist != null)
2092
                {
2093
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2094
                    endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2095
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID();
2096
                    ReleaseCOMObjects(_LmLabelPersist);
2097
                }
2098
                ReleaseCOMObjects(targetLMConnector);
2099
            }
2100
        }
2101

    
2102
        private LMConnector ReModelingLMConnector(LMConnector connector)
2103
        {
2104
            string symbolPath = string.Empty;
2105
            #region get symbol path
2106
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2107
            foreach (LMRepresentation rep in modelItem.Representations)
2108
            {
2109
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2110
                {
2111
                    symbolPath = rep.get_FileName();
2112
                    break;
2113
                }
2114
            }
2115
            #endregion
2116

    
2117
            LMConnector newConnector = null;
2118
            dynamic OID = connector.get_GraphicOID();
2119
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2120
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2121
            int verticesCount = lineStringGeometry.VertexCount;
2122
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2123
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2124

    
2125
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2126
            {
2127
                double[] vertices = null;
2128
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2129
                double x = 0;
2130
                double y = 0;
2131
                lineStringGeometry.GetVertex(1, ref x, ref y);
2132

    
2133
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2134
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2135

    
2136
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2137
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2138
            }
2139
            else
2140
            {
2141
                List<double[]> vertices = new List<double[]>();
2142
                for (int i = 1; i <= verticesCount; i++)
2143
                {
2144
                    double x = 0;
2145
                    double y = 0;
2146
                    lineStringGeometry.GetVertex(i, ref x, ref y);
2147
                    vertices.Add(new double[] { x, y });
2148
                }
2149

    
2150
                for (int i = 0; i < vertices.Count; i++)
2151
                {
2152
                    double[] points = vertices[i];
2153
                    if (i == 0)
2154
                    {
2155
                        if (connector.ConnectItem1SymbolObject != null)
2156
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
2157
                        else
2158
                            placeRunInputs.AddPoint(points[0], points[1]);
2159
                    }
2160
                    else if (i == vertices.Count - 1)
2161
                    {
2162
                        if (connector.ConnectItem2SymbolObject != null)
2163
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
2164
                        else
2165
                            placeRunInputs.AddPoint(points[0], points[1]);
2166
                    }
2167
                    else
2168
                        placeRunInputs.AddPoint(points[0], points[1]);
2169
                }
2170

    
2171
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID);
2172

    
2173
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2174
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2175

    
2176
                foreach (var line in lines)
2177
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
2178
            }
2179

    
2180

    
2181
            return newConnector;
2182
        }
2183

    
2184
        /// <summary>
2185
        /// SpecBreak Modeling 메서드
2186
        /// </summary>
2187
        /// <param name="specBreak"></param>
2188
        private void SpecBreakModeling(SpecBreak specBreak)
2189
        {
2190
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2191
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2192

    
2193
            if (upStreamObj != null &&
2194
                downStreamObj != null)
2195
            {
2196
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2197

    
2198
                if (targetLMConnector != null)
2199
                {
2200
                    foreach (var attribute in specBreak.ATTRIBUTES)
2201
                    {
2202
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2203
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2204
                        {
2205
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2206
                            Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2207
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2208

    
2209
                            if (_LmLabelPersist != null)
2210
                            {
2211
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2212
                                specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2213
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID();
2214
                                ReleaseCOMObjects(_LmLabelPersist);
2215
                            }
2216
                        }
2217
                    }
2218
                    ReleaseCOMObjects(targetLMConnector);
2219
                }
2220
            }
2221
        }
2222

    
2223
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2224
        {
2225
            LMConnector targetConnector = null;
2226
            Symbol targetSymbol = targetObj as Symbol;
2227
            Symbol connectedSymbol = connectedObj as Symbol;
2228
            Line targetLine = targetObj as Line;
2229
            Line connectedLine = connectedObj as Line;
2230
            if (targetSymbol != null && connectedSymbol != null)
2231
            {
2232
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2233
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2234

    
2235
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2236
                {
2237
                    if (connector.get_ItemStatus() != "Active")
2238
                        continue;
2239

    
2240
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2241
                    {
2242
                        targetConnector = connector;
2243
                        break;
2244
                    }
2245
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2246
                    {
2247
                        targetConnector = connector;
2248
                        break;
2249
                    }
2250
                }
2251

    
2252
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2253
                {
2254
                    if (connector.get_ItemStatus() != "Active")
2255
                        continue;
2256

    
2257
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2258
                    {
2259
                        targetConnector = connector;
2260
                        break;
2261
                    }
2262
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2263
                    {
2264
                        targetConnector = connector;
2265
                        break;
2266
                    }
2267
                }
2268

    
2269
                ReleaseCOMObjects(targetLMSymbol);
2270
                ReleaseCOMObjects(connectedLMSymbol);
2271
            }
2272
            else if (targetLine != null && connectedLine != null)
2273
            {
2274
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2275
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2276

    
2277
                if (targetModelItem != null && connectedModelItem != null)
2278
                {
2279
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2280
                    {
2281
                        if (targetConnector != null)
2282
                            break;
2283

    
2284
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2285
                        {
2286
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2287

    
2288
                            if (IsConnected(_LMConnector, connectedModelItem))
2289
                                targetConnector = _LMConnector;
2290
                            else
2291
                                ReleaseCOMObjects(_LMConnector);
2292
                        }
2293
                    }
2294

    
2295
                    ReleaseCOMObjects(targetModelItem);
2296
                }
2297
            }
2298
            else
2299
            {
2300
                LMSymbol connectedLMSymbol = null;
2301
                if (connectedSymbol != null)
2302
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2303
                else if (targetSymbol != null)
2304
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2305
                else
2306
                {
2307

    
2308
                }
2309
                LMModelItem targetModelItem = null;
2310
                if (targetLine != null)
2311
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2312
                else if (connectedLine != null)
2313
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2314
                else
2315
                {
2316

    
2317
                }
2318
                if (connectedLMSymbol != null && targetModelItem != null)
2319
                {
2320
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2321
                    {
2322
                        if (connector.get_ItemStatus() != "Active")
2323
                            continue;
2324

    
2325
                        if (IsConnected(connector, targetModelItem))
2326
                        {
2327
                            targetConnector = connector;
2328
                            break;
2329
                        }
2330
                    }
2331

    
2332
                    if (targetConnector == null)
2333
                    {
2334
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2335
                        {
2336
                            if (connector.get_ItemStatus() != "Active")
2337
                                continue;
2338

    
2339
                            if (IsConnected(connector, targetModelItem))
2340
                            {
2341
                                targetConnector = connector;
2342
                                break;
2343
                            }
2344
                        }
2345
                    }
2346
                }
2347

    
2348
            }
2349

    
2350
            return targetConnector;
2351
        }
2352

    
2353
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2354
        {
2355
            bool result = false;
2356

    
2357
            foreach (LMRepresentation rep in modelItem.Representations)
2358
            {
2359
                if (result)
2360
                    break;
2361

    
2362
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2363
                {
2364
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2365

    
2366
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2367
                        connector.ConnectItem1SymbolObject != null &&
2368
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2369
                    {
2370
                        result = true;
2371
                        ReleaseCOMObjects(_LMConnector);
2372
                        break;
2373
                    }
2374
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2375
                        connector.ConnectItem2SymbolObject != null &&
2376
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2377
                    {
2378
                        result = true;
2379
                        ReleaseCOMObjects(_LMConnector);
2380
                        break;
2381
                    }
2382
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2383
                        connector.ConnectItem1SymbolObject != null &&
2384
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2385
                    {
2386
                        result = true;
2387
                        ReleaseCOMObjects(_LMConnector);
2388
                        break;
2389
                    }
2390
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2391
                        connector.ConnectItem2SymbolObject != null &&
2392
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2393
                    {
2394
                        result = true;
2395
                        ReleaseCOMObjects(_LMConnector);
2396
                        break;
2397
                    }
2398

    
2399
                    ReleaseCOMObjects(_LMConnector);
2400
                }
2401
            }
2402

    
2403

    
2404
            return result;
2405
        }
2406

    
2407
        /// <summary>
2408
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2409
        /// </summary>
2410
        /// <param name="fromModelItemId"></param>
2411
        /// <param name="toModelItemId"></param>
2412
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
2413
        {
2414
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
2415
            _LMAItem item1 = modelItem1.AsLMAItem();
2416
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
2417
            _LMAItem item2 = modelItem2.AsLMAItem();
2418

    
2419
            // item2가 item1으로 조인
2420
            _placement.PIDJoinRuns(ref item1, ref item2);
2421
            item1.Commit();
2422
            item2.Commit();
2423

    
2424
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
2425
            foreach (var line in lines)
2426
                line.SPPID.ModelItemId = toModelItemId;
2427

    
2428
            ReleaseCOMObjects(modelItem1);
2429
            ReleaseCOMObjects(item1);
2430
            ReleaseCOMObjects(modelItem2);
2431
            ReleaseCOMObjects(item2);
2432
        }
2433

    
2434
        /// <summary>
2435
        /// PipeRun을 자동으로 Join하는 메서드
2436
        /// </summary>
2437
        /// <param name="modelItemId"></param>
2438
        private void AutoJoinPipeRun(string modelItemId)
2439
        {
2440
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
2441
            _LMAItem item = modelItem.AsLMAItem();
2442
            if (modelItem.get_ItemStatus() == "Active")
2443
            {
2444
                string modelitemID = item.Id;
2445
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
2446
                string afterModelItemID = item.Id;
2447

    
2448
                if (modelitemID != afterModelItemID)
2449
                {
2450
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
2451
                    foreach (var line in lines)
2452
                        line.SPPID.ModelItemId = afterModelItemID;
2453
                }
2454
                item.Commit();
2455
            }
2456

    
2457
            ReleaseCOMObjects(modelItem);
2458
            ReleaseCOMObjects(item);
2459
        }
2460

    
2461
        /// <summary>
2462
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
2463
        /// </summary>
2464
        /// <param name="run"></param>
2465
        private void JoinRunLine(LineRun run)
2466
        {
2467
            string modelItemId = string.Empty;
2468
            foreach (var item in run.RUNITEMS)
2469
            {
2470
                if (item.GetType() == typeof(Line))
2471
                {
2472
                    Line line = item as Line;
2473
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
2474
                    modelItemId = line.SPPID.ModelItemId;
2475
                }
2476
            }
2477
        }
2478

    
2479
        /// <summary>
2480
        /// PipeRun의 좌표를 가져오는 메서드
2481
        /// </summary>
2482
        /// <param name="modelId"></param>
2483
        /// <returns></returns>
2484
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2485
        {
2486
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2487
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2488

    
2489
            if (modelItem != null)
2490
            {
2491
                foreach (LMRepresentation rep in modelItem.Representations)
2492
                {
2493
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2494
                    {
2495
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2496
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2497
                        dynamic OID = rep.get_GraphicOID();
2498
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2499
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2500
                        int verticesCount = lineStringGeometry.VertexCount;
2501
                        double[] vertices = null;
2502
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2503
                        for (int i = 0; i < verticesCount; i++)
2504
                        {
2505
                            double x = 0;
2506
                            double y = 0;
2507
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2508
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
2509
                        }
2510
                    }
2511
                }
2512

    
2513
                ReleaseCOMObjects(modelItem);
2514
            }
2515

    
2516
            return connectorVertices;
2517
        }
2518

    
2519
        /// <summary>
2520
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2521
        /// </summary>
2522
        /// <param name="connectorVertices"></param>
2523
        /// <param name="connX"></param>
2524
        /// <param name="connY"></param>
2525
        /// <returns></returns>
2526
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2527
        {
2528
            double length = double.MaxValue;
2529
            LMConnector targetConnector = null;
2530
            foreach (var item in connectorVertices)
2531
            {
2532
                List<double[]> points = item.Value;
2533
                for (int i = 0; i < points.Count - 1; i++)
2534
                {
2535
                    double[] point1 = points[i];
2536
                    double[] point2 = points[i + 1];
2537
                    double x1 = Math.Min(point1[0], point2[0]);
2538
                    double y1 = Math.Min(point1[1], point2[1]);
2539
                    double x2 = Math.Max(point1[0], point2[0]);
2540
                    double y2 = Math.Max(point1[1], point2[1]);
2541

    
2542
                    if ((x1 <= connX && x2 >= connX) ||
2543
                        (y1 <= connY && y2 >= connY))
2544
                    {
2545
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2546
                        if (length >= distance)
2547
                        {
2548
                            targetConnector = item.Key;
2549
                            length = distance;
2550
                        }
2551

    
2552
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2553
                        if (length >= distance)
2554
                        {
2555
                            targetConnector = item.Key;
2556
                            length = distance;
2557
                        }
2558
                    }
2559
                }
2560
            }
2561

    
2562
            // 못찾았을때.
2563
            length = double.MaxValue;
2564
            if (targetConnector == null)
2565
            {
2566
                foreach (var item in connectorVertices)
2567
                {
2568
                    List<double[]> points = item.Value;
2569

    
2570
                    foreach (double[] point in points)
2571
                    {
2572
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2573
                        if (length >= distance)
2574
                        {
2575
                            targetConnector = item.Key;
2576
                            length = distance;
2577
                        }
2578
                    }
2579
                }
2580
            }
2581

    
2582
            return targetConnector;
2583
        }
2584

    
2585
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
2586
        {
2587
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
2588

    
2589
            double length = double.MaxValue;
2590
            LMConnector targetConnector = null;
2591
            double[] resultPoint = null;
2592
            List<double[]> targetVertices = null;
2593

    
2594
            // Vertices 포인트에 제일 가까운곳
2595
            foreach (var item in vertices)
2596
            {
2597
                List<double[]> points = item.Value;
2598
                for (int i = 0; i < points.Count; i++)
2599
                {
2600
                    double[] point = points[i];
2601
                    double tempX = point[0];
2602
                    double tempY = point[1];
2603

    
2604
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
2605
                    if (length >= distance)
2606
                    {
2607
                        targetConnector = item.Key;
2608
                        length = distance;
2609
                        resultPoint = point;
2610
                        targetVertices = item.Value;
2611
                    }
2612
                }
2613
            }
2614

    
2615
            // Vertices Cross에 제일 가까운곳
2616
            foreach (var item in vertices)
2617
            {
2618
                List<double[]> points = item.Value;
2619
                for (int i = 0; i < points.Count - 1; i++)
2620
                {
2621
                    double[] point1 = points[i];
2622
                    double[] point2 = points[i + 1];
2623

    
2624
                    double maxLineX = Math.Max(point1[0], point2[0]);
2625
                    double minLineX = Math.Min(point1[0], point2[0]);
2626
                    double maxLineY = Math.Max(point1[1], point2[1]);
2627
                    double minLineY = Math.Min(point1[1], point2[1]);
2628

    
2629
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2630

    
2631
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y, point1[0], point1[1], point2[0], point2[1]);
2632
                    if (crossingPoint != null)
2633
                    {
2634
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
2635
                        if (length >= distance)
2636
                        {
2637
                            if (slope == SlopeType.Slope &&
2638
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2639
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2640
                            {
2641
                                targetConnector = item.Key;
2642
                                length = distance;
2643
                                resultPoint = crossingPoint;
2644
                                targetVertices = item.Value;
2645
                            }
2646
                            else if (slope == SlopeType.HORIZONTAL &&
2647
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2648
                            {
2649
                                targetConnector = item.Key;
2650
                                length = distance;
2651
                                resultPoint = crossingPoint;
2652
                                targetVertices = item.Value;
2653
                            }
2654
                            else if (slope == SlopeType.VERTICAL &&
2655
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2656
                            {
2657
                                targetConnector = item.Key;
2658
                                length = distance;
2659
                                resultPoint = crossingPoint;
2660
                                targetVertices = item.Value;
2661
                            }
2662
                        }
2663
                    }
2664
                }
2665
            }
2666

    
2667
            foreach (var item in vertices)
2668
                if (item.Key != null && item.Key != targetConnector)
2669
                    ReleaseCOMObjects(item.Key);
2670

    
2671
            if (SPPIDUtil.IsBranchLine(line, targetLine))
2672
            {
2673
                double tempResultX = resultPoint[0];
2674
                double tempResultY = resultPoint[1];
2675
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
2676

    
2677
                GridSetting gridSetting = GridSetting.GetInstance();
2678

    
2679
                for (int i = 0; i < targetVertices.Count; i++)
2680
                {
2681
                    double[] point = targetVertices[i];
2682
                    double tempX = targetVertices[i][0];
2683
                    double tempY = targetVertices[i][1];
2684
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
2685
                    if (tempX == tempResultX && tempY == tempResultY)
2686
                    {
2687
                        if (i == 0)
2688
                        {
2689
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
2690
                            bool containZeroLength = false;
2691
                            if (connSymbol != null)
2692
                            {
2693
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2694
                                {
2695
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2696
                                        containZeroLength = true;
2697
                                }
2698
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2699
                                {
2700
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2701
                                        containZeroLength = true;
2702
                                }
2703
                            }
2704

    
2705
                            if (connSymbol == null ||
2706
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2707
                                containZeroLength)
2708
                            {
2709
                                bool bCalcX = false;
2710
                                bool bCalcY = false;
2711
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2712
                                    bCalcX = true;
2713
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2714
                                    bCalcY = true;
2715
                                else
2716
                                {
2717
                                    bCalcX = true;
2718
                                    bCalcY = true;
2719
                                }
2720

    
2721
                                if (bCalcX)
2722
                                {
2723
                                    double nextX = targetVertices[i + 1][0];
2724
                                    double newX = 0;
2725
                                    if (nextX > tempX)
2726
                                    {
2727
                                        newX = tempX + gridSetting.Length;
2728
                                        if (newX > nextX)
2729
                                            newX = (point[0] + nextX) / 2;
2730
                                    }
2731
                                    else
2732
                                    {
2733
                                        newX = tempX - gridSetting.Length;
2734
                                        if (newX < nextX)
2735
                                            newX = (point[0] + nextX) / 2;
2736
                                    }
2737
                                    resultPoint = new double[] { newX, resultPoint[1] };
2738
                                }
2739

    
2740
                                if (bCalcY)
2741
                                {
2742
                                    double nextY = targetVertices[i + 1][1];
2743
                                    double newY = 0;
2744
                                    if (nextY > tempY)
2745
                                    {
2746
                                        newY = tempY + gridSetting.Length;
2747
                                        if (newY > nextY)
2748
                                            newY = (point[1] + nextY) / 2;
2749
                                    }
2750
                                    else
2751
                                    {
2752
                                        newY = tempY - gridSetting.Length;
2753
                                        if (newY < nextY)
2754
                                            newY = (point[1] + nextY) / 2;
2755
                                    }
2756
                                    resultPoint = new double[] { resultPoint[0], newY };
2757
                                }
2758
                            }
2759
                        }
2760
                        else if (i == targetVertices.Count - 1)
2761
                        {
2762
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
2763
                            bool containZeroLength = false;
2764
                            if (connSymbol != null)
2765
                            {
2766
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2767
                                {
2768
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2769
                                        containZeroLength = true;
2770
                                }
2771
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2772
                                {
2773
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2774
                                        containZeroLength = true;
2775
                                }
2776
                            }
2777

    
2778
                            if (connSymbol == null ||
2779
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2780
                                containZeroLength)
2781
                            {
2782
                                bool bCalcX = false;
2783
                                bool bCalcY = false;
2784
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2785
                                    bCalcX = true;
2786
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2787
                                    bCalcY = true;
2788
                                else
2789
                                {
2790
                                    bCalcX = true;
2791
                                    bCalcY = true;
2792
                                }
2793

    
2794
                                if (bCalcX)
2795
                                {
2796
                                    double nextX = targetVertices[i - 1][0];
2797
                                    double newX = 0;
2798
                                    if (nextX > tempX)
2799
                                    {
2800
                                        newX = tempX + gridSetting.Length;
2801
                                        if (newX > nextX)
2802
                                            newX = (point[0] + nextX) / 2;
2803
                                    }
2804
                                    else
2805
                                    {
2806
                                        newX = tempX - gridSetting.Length;
2807
                                        if (newX < nextX)
2808
                                            newX = (point[0] + nextX) / 2;
2809
                                    }
2810
                                    resultPoint = new double[] { newX, resultPoint[1] };
2811
                                }
2812

    
2813
                                if (bCalcY)
2814
                                {
2815
                                    double nextY = targetVertices[i - 1][1];
2816
                                    double newY = 0;
2817
                                    if (nextY > tempY)
2818
                                    {
2819
                                        newY = tempY + gridSetting.Length;
2820
                                        if (newY > nextY)
2821
                                            newY = (point[1] + nextY) / 2;
2822
                                    }
2823
                                    else
2824
                                    {
2825
                                        newY = tempY - gridSetting.Length;
2826
                                        if (newY < nextY)
2827
                                            newY = (point[1] + nextY) / 2;
2828
                                    }
2829
                                    resultPoint = new double[] { resultPoint[0], newY };
2830
                                }
2831
                            }
2832
                        }
2833
                        break;
2834
                    }
2835
                }
2836
            }
2837

    
2838
            x = resultPoint[0];
2839
            y = resultPoint[1];
2840

    
2841
            return targetConnector;
2842
        }
2843

    
2844
        /// <summary>
2845
        /// Line Number Symbol을 실제로 Modeling하는 메서드
2846
        /// </summary>
2847
        /// <param name="lineNumber"></param>
2848
        private void LineNumberModeling(LineNumber lineNumber)
2849
        {
2850
            object obj = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE);
2851
            if (obj != null)
2852
            {
2853
                Line line = obj as Line;
2854
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2855
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
2856
                if (connectedLMConnector != null)
2857
                {
2858
                    double x = 0;
2859
                    double y = 0;
2860
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
2861

    
2862
                    Array points = new double[] { 0, x, y };
2863
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
2864

    
2865
                    foreach (var item in connectorVertices)
2866
                        ReleaseCOMObjects(item.Key);
2867
                    if (_LmLabelPresist != null)
2868
                    {
2869
                        _LmLabelPresist.Commit();
2870
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
2871
                        ReleaseCOMObjects(_LmLabelPresist);
2872
                    }
2873
                    else
2874
                    {
2875

    
2876
                    }
2877
                }
2878
            }
2879
        }
2880

    
2881
        /// <summary>
2882
        /// Flow Mark Modeling
2883
        /// </summary>
2884
        /// <param name="line"></param>
2885
        private void FlowMarkModeling(Line line)
2886
        {
2887
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
2888
            {
2889
                SlopeType targetSlopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
2890
                string mappingPath = _ETCSetting.FlowMarkSymbolPath;
2891
                double percent = line.FLOWMARK_PERCENT;
2892
                double tempX = 0;
2893
                double tempY = 0;
2894

    
2895
                double gapX;
2896
                double gapY;
2897
                // ID2 기준의 Gap을 구함
2898
                if (percent == 0)
2899
                {
2900
                    gapX = 0;
2901
                    gapY = 0;
2902
                }
2903
                else
2904
                {
2905
                    gapX = Math.Abs(line.SPPID.START_X - line.SPPID.END_X) / 100 * percent;
2906
                    gapY = Math.Abs(line.SPPID.START_Y - line.SPPID.END_Y) / 100 * percent;
2907
                }
2908

    
2909
                if (line.SPPID.START_X < line.SPPID.END_X)
2910
                    tempX = line.SPPID.START_X + gapX;
2911
                else
2912
                    tempX = line.SPPID.START_X - gapX;
2913

    
2914
                if (line.SPPID.START_Y < line.SPPID.END_Y)
2915
                    tempY = line.SPPID.START_Y + gapY;
2916
                else
2917
                    tempY = line.SPPID.START_Y - gapY;
2918

    
2919

    
2920

    
2921
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
2922
                LMConnector _TargetItem = null;
2923
                double distance = double.MaxValue;
2924
                double[] startPoint = null;
2925
                double[] endPoint = null;
2926
                // ID2의 기준 Gap으로 제일 가까운 Line 찾음(Slope도 같은조건)
2927
                foreach (var item in connectorVertices)
2928
                {
2929
                    for (int i = 0; i < item.Value.Count - 1; i++)
2930
                    {
2931
                        List<double[]> points = item.Value;
2932
                        double[] point1 = points[i];
2933
                        double[] point2 = points[i + 1];
2934

    
2935
                        SlopeType slopeType = SPPIDUtil.CalcSlope(point1[0], point1[1], point2[0], point2[1]);
2936
                        if (slopeType == targetSlopeType)
2937
                        {
2938
                            double result = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], tempX, tempY);
2939
                            if (result < distance)
2940
                            {
2941
                                distance = result;
2942
                                _TargetItem = item.Key;
2943

    
2944
                                startPoint = point1;
2945
                                endPoint = point2;
2946
                            }
2947

    
2948
                            result = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], tempX, tempY);
2949
                            if (result < distance)
2950
                            {
2951
                                distance = result;
2952
                                _TargetItem = item.Key;
2953

    
2954
                                startPoint = point1;
2955
                                endPoint = point2;
2956
                            }
2957
                        }
2958
                    }
2959
                }
2960

    
2961
                if (_TargetItem != null)
2962
                {
2963
                    double x = 0;
2964
                    double y = 0;
2965
                    double angle = 0;
2966
                    // SPPID 기준의 Gap으로 실 좌표를 구함
2967
                    if (percent == 0)
2968
                    {
2969
                        gapX = 0;
2970
                        gapY = 0;
2971
                    }
2972
                    else
2973
                    {
2974
                        gapX = Math.Abs(startPoint[0] - endPoint[0]) / 100 * percent;
2975
                        gapY = Math.Abs(startPoint[1] - endPoint[1]) / 100 * percent;
2976
                    }
2977

    
2978
                    if (startPoint[0] < endPoint[0])
2979
                        x = startPoint[0] + gapX;
2980
                    else
2981
                        x = startPoint[0] - gapX;
2982

    
2983
                    if (startPoint[1] < endPoint[1])
2984
                        y = startPoint[1] + gapY;
2985
                    else
2986
                        y = startPoint[1] - gapY;
2987

    
2988
                    if (targetSlopeType == SlopeType.HORIZONTAL)
2989
                    {
2990
                        if (startPoint[0] < endPoint[0])
2991
                            angle = 0;
2992
                        else
2993
                            angle = Math.PI;
2994
                    }
2995
                    // 90 270
2996
                    else if (targetSlopeType == SlopeType.VERTICAL)
2997
                    {
2998
                        if (startPoint[1] < endPoint[1])
2999
                            angle = 90 * Math.PI / 180;
3000
                        else
3001
                            angle = 270 * Math.PI / 180;
3002
                    }
3003

    
3004
                    LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: 0, Rotation: angle, TargetItem: _TargetItem);
3005

    
3006
                    if (_LMSymbol != null)
3007
                    {
3008
                        ReleaseCOMObjects(_LMSymbol);
3009
                    }
3010

    
3011
                }
3012

    
3013
                foreach (var item in connectorVertices)
3014
                    ReleaseCOMObjects(item.Key);
3015
            }
3016
        }
3017

    
3018
        /// <summary>
3019
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
3020
        /// </summary>
3021
        /// <param name="lineNumber"></param>
3022
        private void InputLineNumberAttribute(LineNumber lineNumber)
3023
        {
3024
            foreach (LineRun run in lineNumber.RUNS)
3025
            {
3026
                foreach (var item in run.RUNITEMS)
3027
                {
3028
                    if (item.GetType() == typeof(Symbol))
3029
                    {
3030
                        Symbol symbol = item as Symbol;
3031
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3032
                        if (_LMSymbol != null)
3033
                        {
3034
                            LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3035

    
3036
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3037
                            {
3038
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3039
                                {
3040
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3041
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3042
                                    {
3043
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3044
                                        if (_LMAAttribute != null)
3045
                                        {
3046
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3047
                                                _LMAAttribute.set_Value(attribute.VALUE);
3048
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3049
                                                _LMAAttribute.set_Value(attribute.VALUE);
3050
                                        }
3051
                                    }
3052
                                }
3053
                                _LMModelItem.Commit();
3054
                            }
3055
                            if (_LMModelItem != null)
3056
                                ReleaseCOMObjects(_LMModelItem);
3057
                        }
3058
                        if (_LMSymbol != null)
3059
                            ReleaseCOMObjects(_LMSymbol);
3060
                    }
3061
                    else if (item.GetType() == typeof(Line))
3062
                    {
3063
                        Line line = item as Line;
3064
                        if (line != null)
3065
                        {
3066
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3067
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3068
                            {
3069
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3070
                                {
3071
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3072
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3073
                                    {
3074
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3075
                                        if (_LMAAttribute != null)
3076
                                        {
3077
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3078
                                                _LMAAttribute.set_Value(attribute.VALUE);
3079
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3080
                                                _LMAAttribute.set_Value(attribute.VALUE);
3081

    
3082
                                        }
3083
                                    }
3084
                                }
3085
                                _LMModelItem.Commit();
3086
                            }
3087
                            if (_LMModelItem != null)
3088
                                ReleaseCOMObjects(_LMModelItem);
3089
                        }
3090
                    }
3091
                }
3092
            }
3093
        }
3094

    
3095
        /// <summary>
3096
        /// Symbol Attribute 입력 메서드
3097
        /// </summary>
3098
        /// <param name="item"></param>
3099
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3100
        {
3101

    
3102
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3103
            string sRep = null;
3104
            if (targetItem.GetType() == typeof(Symbol))
3105
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3106
            else if (targetItem.GetType() == typeof(Equipment))
3107
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3108

    
3109
            if (!string.IsNullOrEmpty(sRep))
3110
            {
3111
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3112
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3113
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3114

    
3115
                foreach (var item in targetAttributes)
3116
                {
3117
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3118
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3119
                    {
3120
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3121
                        if (_Attribute != null)
3122
                            _Attribute.set_Value(item.VALUE);
3123
                    }
3124
                }
3125
                _LMModelItem.Commit();
3126

    
3127
                ReleaseCOMObjects(_Attributes);
3128
                ReleaseCOMObjects(_LMModelItem);
3129
                ReleaseCOMObjects(_LMSymbol);
3130
            }
3131
        }
3132

    
3133
        /// <summary>
3134
        /// Input SpecBreak Attribute
3135
        /// </summary>
3136
        /// <param name="specBreak"></param>
3137
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3138
        {
3139
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3140
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3141

    
3142
            if (upStreamObj != null &&
3143
                downStreamObj != null)
3144
            {
3145
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3146

    
3147
                if (targetLMConnector != null)
3148
                {
3149
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
3150
                    {
3151
                        string symbolPath = _LMLabelPersist.get_FileName();
3152
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
3153
                        if (mapping != null)
3154
                        {
3155
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
3156
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3157
                            {
3158
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
3159
                                if (values.Length == 2)
3160
                                {
3161
                                    string upStreamValue = values[0];
3162
                                    string downStreamValue = values[1];
3163

    
3164
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3165
                                }
3166
                            }
3167
                        }
3168
                    }
3169

    
3170
                    ReleaseCOMObjects(targetLMConnector);
3171
                }
3172
            }
3173

    
3174

    
3175
            #region 내부에서만 쓰는 메서드
3176
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
3177
            {
3178
                Symbol upStreamSymbol = _upStreamObj as Symbol;
3179
                Line upStreamLine = _upStreamObj as Line;
3180
                Symbol downStreamSymbol = _downStreamObj as Symbol;
3181
                Line downStreamLine = _downStreamObj as Line;
3182
                // 둘다 Line일 경우
3183
                if (upStreamLine != null && downStreamLine != null)
3184
                {
3185
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3186
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3187
                }
3188
                // 둘다 Symbol일 경우
3189
                else if (upStreamSymbol != null && downStreamSymbol != null)
3190
                {
3191
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
3192
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3193
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3194

    
3195
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3196
                    {
3197
                        if (connector.get_ItemStatus() != "Active")
3198
                            continue;
3199

    
3200
                        if (connector.Id != zeroLenthConnector.Id)
3201
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3202
                    }
3203

    
3204
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3205
                    {
3206
                        if (connector.get_ItemStatus() != "Active")
3207
                            continue;
3208

    
3209
                        if (connector.Id != zeroLenthConnector.Id)
3210
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3211
                    }
3212

    
3213
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3214
                    {
3215
                        if (connector.get_ItemStatus() != "Active")
3216
                            continue;
3217

    
3218
                        if (connector.Id != zeroLenthConnector.Id)
3219
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3220
                    }
3221

    
3222
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3223
                    {
3224
                        if (connector.get_ItemStatus() != "Active")
3225
                            continue;
3226

    
3227
                        if (connector.Id != zeroLenthConnector.Id)
3228
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3229
                    }
3230

    
3231
                    ReleaseCOMObjects(zeroLenthConnector);
3232
                    ReleaseCOMObjects(upStreamLMSymbol);
3233
                    ReleaseCOMObjects(downStreamLMSymbol);
3234
                }
3235
                else if (upStreamSymbol != null && downStreamLine != null)
3236
                {
3237
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3238
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3239
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3240

    
3241
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3242
                    {
3243
                        if (connector.get_ItemStatus() != "Active")
3244
                            continue;
3245

    
3246
                        if (connector.Id != zeroLenthConnector.Id)
3247
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3248
                    }
3249

    
3250
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3251
                    {
3252
                        if (connector.get_ItemStatus() != "Active")
3253
                            continue;
3254

    
3255
                        if (connector.Id != zeroLenthConnector.Id)
3256
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3257
                    }
3258

    
3259
                    ReleaseCOMObjects(zeroLenthConnector);
3260
                    ReleaseCOMObjects(upStreamLMSymbol);
3261
                }
3262
                else if (upStreamLine != null && downStreamSymbol != null)
3263
                {
3264
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3265
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3266
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3267

    
3268
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3269
                    {
3270
                        if (connector.get_ItemStatus() != "Active")
3271
                            continue;
3272

    
3273
                        if (connector.Id != zeroLenthConnector.Id)
3274
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3275
                    }
3276

    
3277
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3278
                    {
3279
                        if (connector.get_ItemStatus() != "Active")
3280
                            continue;
3281

    
3282
                        if (connector.Id != zeroLenthConnector.Id)
3283
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3284
                    }
3285

    
3286
                    ReleaseCOMObjects(zeroLenthConnector);
3287
                    ReleaseCOMObjects(downStreamLMSymbol);
3288
                }
3289
            }
3290

    
3291
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3292
            {
3293
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3294
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3295
                {
3296
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3297
                    if (_LMAAttribute != null)
3298
                    {
3299
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3300
                            _LMAAttribute.set_Value(value);
3301
                        else if (_LMAAttribute.get_Value() != value)
3302
                            _LMAAttribute.set_Value(value);
3303
                    }
3304

    
3305
                    _LMModelItem.Commit();
3306
                }
3307
                if (_LMModelItem != null)
3308
                    ReleaseCOMObjects(_LMModelItem);
3309
            }
3310

    
3311
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3312
            {
3313
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3314
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3315
                {
3316
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3317
                    if (_LMAAttribute != null)
3318
                    {
3319
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3320
                            _LMAAttribute.set_Value(value);
3321
                        else if (_LMAAttribute.get_Value() != value)
3322
                            _LMAAttribute.set_Value(value);
3323
                    }
3324

    
3325
                    _LMModelItem.Commit();
3326
                }
3327
                if (_LMModelItem != null)
3328
                    ReleaseCOMObjects(_LMModelItem);
3329
            }
3330
            #endregion
3331
        }
3332

    
3333
        /// <summary>
3334
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3335
        /// </summary>
3336
        /// <param name="text"></param>
3337
        private void TextModeling(Text text)
3338
        {
3339
            LMSymbol _LMSymbol = null;
3340
            LMConnector connectedLMConnector = null;
3341
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
3342
            if (text.ASSOCIATION)
3343
            {
3344
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
3345
                if (owner.GetType() == typeof(Symbol))
3346
                {
3347
                    Symbol symbol = owner as Symbol;
3348
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3349
                    if (_LMSymbol != null)
3350
                    {
3351
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3352
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3353
                        {
3354
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3355

    
3356
                            if (mapping != null)
3357
                            {
3358
                                double x = 0;
3359
                                double y = 0;
3360

    
3361
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3362
                                Array array = new double[] { 0, x, y };
3363

    
3364
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3365
                                if (_LMLabelPersist != null)
3366
                                {
3367
                                    _LMLabelPersist.Commit();
3368
                                    ReleaseCOMObjects(_LMLabelPersist);
3369
                                }
3370
                            }
3371
                        }
3372
                    }
3373
                }
3374
                else if (owner.GetType() == typeof(Line))
3375
                {
3376
                    Line line = owner as Line;
3377
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3378
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
3379

    
3380
                    if (connectedLMConnector != null)
3381
                    {
3382
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3383
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3384
                        {
3385
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3386

    
3387
                            if (mapping != null)
3388
                            {
3389
                                double x = 0;
3390
                                double y = 0;
3391

    
3392
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3393
                                Array array = new double[] { 0, x, y };
3394

    
3395
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3396
                                if (_LMLabelPersist != null)
3397
                                {
3398
                                    _LMLabelPersist.Commit();
3399
                                    ReleaseCOMObjects(_LMLabelPersist);
3400
                                }
3401
                            }
3402
                        }
3403
                    }
3404
                }
3405
            }
3406
            else
3407
            {
3408
                LMItemNote _LMItemNote = null;
3409
                LMAAttribute _LMAAttribute = null;
3410

    
3411
                double x = 0;
3412
                double y = 0;
3413
                double angle = text.ANGLE;
3414
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3415

    
3416
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3417
                _LMSymbol.Commit();
3418
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3419
                _LMItemNote.Commit();
3420
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3421
                _LMAAttribute.set_Value(text.VALUE);
3422
                _LMItemNote.Commit();
3423

    
3424
                if (_LMAAttribute != null)
3425
                    ReleaseCOMObjects(_LMAAttribute);
3426
                if (_LMItemNote != null)
3427
                    ReleaseCOMObjects(_LMItemNote);
3428
            }
3429
            if (_LMSymbol != null)
3430
                ReleaseCOMObjects(_LMSymbol);
3431
        }
3432

    
3433
        /// <summary>
3434
        /// Note Modeling
3435
        /// </summary>
3436
        /// <param name="note"></param>
3437
        private void NoteModeling(Note note)
3438
        {
3439
            LMSymbol _LMSymbol = null;
3440
            LMItemNote _LMItemNote = null;
3441
            LMAAttribute _LMAAttribute = null;
3442

    
3443
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
3444
            {
3445
                double x = 0;
3446
                double y = 0;
3447

    
3448
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
3449

    
3450
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3451
                _LMSymbol.Commit();
3452
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3453
                _LMItemNote.Commit();
3454
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3455
                _LMAAttribute.set_Value(note.VALUE);
3456
                _LMItemNote.Commit();
3457
            }
3458

    
3459
            if (_LMAAttribute != null)
3460
                ReleaseCOMObjects(_LMAAttribute);
3461
            if (_LMItemNote != null)
3462
                ReleaseCOMObjects(_LMItemNote);
3463
            if (_LMSymbol != null)
3464
                ReleaseCOMObjects(_LMSymbol);
3465
        }
3466

    
3467
        /// <summary>
3468
        /// Note Symbol Modeling
3469
        /// </summary>
3470
        /// <param name="symbol"></param>
3471
        private void NoteSymbolModeling(Symbol symbol)
3472
        {
3473
            if (symbol.TYPE == "Notes")
3474
            {
3475
                string mappingPath = symbol.SPPID.MAPPINGNAME;
3476
                double x = symbol.SPPID.ORIGINAL_X;
3477
                double y = symbol.SPPID.ORIGINAL_Y;
3478
                int mirror = 0;
3479
                double angle = symbol.ANGLE;
3480

    
3481
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
3482
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
3483
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
3484

    
3485
                ReleaseCOMObjects(_LMSymbol);
3486

    
3487
                InputSymbolAttribute(symbol, symbol.ATTRIBUTES);
3488
            }
3489
        }
3490

    
3491
        /// <summary>
3492
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
3493
        /// </summary>
3494
        /// <param name="x"></param>
3495
        /// <param name="y"></param>
3496
        /// <param name="originX"></param>
3497
        /// <param name="originY"></param>
3498
        /// <param name="SPPIDLabelLocation"></param>
3499
        /// <param name="location"></param>
3500
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
3501
        {
3502
            if (location == Location.None)
3503
            {
3504
                x = originX;
3505
                y = originY;
3506
            }
3507
            else
3508
            {
3509
                if (location.HasFlag(Location.Center))
3510
                {
3511
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
3512
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
3513
                }
3514

    
3515
                if (location.HasFlag(Location.Left))
3516
                    x = SPPIDLabelLocation.X1;
3517
                else if (location.HasFlag(Location.Right))
3518
                    x = SPPIDLabelLocation.X2;
3519

    
3520
                if (location.HasFlag(Location.Down))
3521
                    y = SPPIDLabelLocation.Y1;
3522
                else if (location.HasFlag(Location.Up))
3523
                    y = SPPIDLabelLocation.Y2;
3524
            }
3525
        }
3526

    
3527
        /// <summary>
3528
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
3529
        /// 1. Angle Valve
3530
        /// 2. 3개로 이루어진 Symbol Group
3531
        /// </summary>
3532
        /// <returns></returns>
3533
        private List<Symbol> GetPrioritySymbol()
3534
        {
3535
            DataTable symbolTable = document.SymbolTable;
3536
            // List에 순서대로 쌓는다.
3537
            List<Symbol> symbols = new List<Symbol>();
3538

    
3539
            // Angle Valve 부터
3540
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
3541
            {
3542
                if (!symbols.Contains(symbol))
3543
                {
3544
                    double originX = 0;
3545
                    double originY = 0;
3546

    
3547
                    // ID2 Table에서 Original Point 가져옴.
3548
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString();
3549
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
3550

    
3551
                    SlopeType slopeType1 = SlopeType.None;
3552
                    SlopeType slopeType2 = SlopeType.None;
3553
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
3554
                    {
3555
                        double connectorX = 0;
3556
                        double connectorY = 0;
3557
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3558
                        if (slopeType1 == SlopeType.None)
3559
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3560
                        else
3561
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3562
                    }
3563

    
3564
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3565
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3566
                        symbols.Add(symbol);
3567
                }
3568
            }
3569

    
3570
            List<Symbol> tempSymbols = new List<Symbol>();
3571
            // Conn 갯수 기준
3572
            foreach (var item in document.SYMBOLS)
3573
            {
3574
                if (!symbols.Contains(item))
3575
                    tempSymbols.Add(item);
3576
            }
3577
            tempSymbols.Sort(SortSymbolPriority);
3578
            symbols.AddRange(tempSymbols);
3579

    
3580
            return symbols;
3581
        }
3582

    
3583
        private void SetPriorityLine()
3584
        {
3585
            document.LINES.Sort(SortLinePriority);
3586

    
3587
            int SortLinePriority(Line a, Line b)
3588
            {
3589
                // Branch 없는것부터
3590
                int branchRetval = CompareBranchLine(a, b);
3591
                if (branchRetval != 0)
3592
                {
3593
                    return branchRetval;
3594
                }
3595
                else
3596
                {
3597
                    // Symbol 연결 갯수
3598
                    int connSymbolRetval = CompareConnSymbol(a, b);
3599
                    if (connSymbolRetval != 0)
3600
                    {
3601
                        return connSymbolRetval;
3602
                    }
3603
                    else
3604
                    {
3605
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
3606
                        int connItemRetval = CompareConnItem(a, b);
3607
                        if (connItemRetval != 0)
3608
                        {
3609
                            return connItemRetval;
3610
                        }
3611
                        else
3612
                        {
3613
                            // ConnectedItem이 없는것
3614
                            int noneConnRetval = CompareNoneConn(a, b);
3615
                            if (noneConnRetval != 0)
3616
                            {
3617
                                return noneConnRetval;
3618
                            }
3619
                            else
3620
                            {
3621

    
3622
                            }
3623
                        }
3624
                    }
3625
                }
3626

    
3627
                return 0;
3628
            }
3629

    
3630
            int CompareConnSymbol(Line a, Line b)
3631
            {
3632
                List<Connector> connectorsA = a.CONNECTORS
3633
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3634
                    .ToList();
3635

    
3636
                List<Connector> connectorsB = b.CONNECTORS
3637
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3638
                    .ToList();
3639

    
3640
                // 오름차순
3641
                return connectorsB.Count.CompareTo(connectorsA.Count);
3642
            }
3643

    
3644
            int CompareConnItem(Line a, Line b)
3645
            {
3646
                List<Connector> connectorsA = a.CONNECTORS
3647
                    .Where(conn => conn.ConnectedObject != null && 
3648
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
3649
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
3650
                    .ToList();
3651

    
3652
                List<Connector> connectorsB = b.CONNECTORS
3653
                    .Where(conn => conn.ConnectedObject != null &&
3654
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
3655
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
3656
                    .ToList();
3657

    
3658
                // 오름차순
3659
                return connectorsB.Count.CompareTo(connectorsA.Count);
3660
            }
3661

    
3662
            int CompareBranchLine(Line a, Line b)
3663
            {
3664
                List<Connector> connectorsA = a.CONNECTORS
3665
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
3666
                    .ToList();
3667
                List<Connector> connectorsB = b.CONNECTORS
3668
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
3669
                    .ToList();
3670

    
3671
                // 내림차순
3672
                return connectorsA.Count.CompareTo(connectorsB.Count);
3673
            }
3674

    
3675
            int CompareNoneConn(Line a, Line b)
3676
            {
3677
                List<Connector> connectorsA = a.CONNECTORS
3678
                    .Where(conn => conn.ConnectedObject == null)
3679
                    .ToList();
3680

    
3681
                List<Connector> connectorsB = b.CONNECTORS
3682
                    .Where(conn => conn.ConnectedObject == null)
3683
                    .ToList();
3684

    
3685
                // 오름차순
3686
                return connectorsB.Count.CompareTo(connectorsA.Count);
3687
            }
3688
        }
3689

    
3690
        private void SortBranchLines()
3691
        {
3692
            NewBranchLines.Sort(SortBranchLine);
3693
            int SortBranchLine(Line a, Line b)
3694
            {
3695
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3696
                 x.ConnectedObject.GetType() == typeof(Line) &&
3697
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
3698
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3699

    
3700
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3701
                 x.ConnectedObject.GetType() == typeof(Line) &&
3702
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
3703
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3704

    
3705
                // 내림차순
3706
                return countA.CompareTo(countB);
3707
            }
3708
        }
3709

    
3710
        private static int SortSymbolPriority(Symbol a, Symbol b)
3711
        {
3712
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3713
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3714
            int retval = countB.CompareTo(countA);
3715
            if (retval != 0)
3716
                return retval;
3717
            else
3718
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
3719
        }
3720

    
3721
        /// <summary>
3722
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
3723
        /// </summary>
3724
        /// <param name="graphicOID"></param>
3725
        /// <param name="milliseconds"></param>
3726
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
3727
        {
3728
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
3729
            {
3730
                double minX = 0;
3731
                double minY = 0;
3732
                double maxX = 0;
3733
                double maxY = 0;
3734
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
3735
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
3736

    
3737
                Thread.Sleep(milliseconds);
3738
            }
3739
        }
3740

    
3741
        /// <summary>
3742
        /// ComObject를 Release
3743
        /// </summary>
3744
        /// <param name="objVars"></param>
3745
        public void ReleaseCOMObjects(params object[] objVars)
3746
        {
3747
            int intNewRefCount = 0;
3748
            foreach (object obj in objVars)
3749
            {
3750
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
3751
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
3752
            }
3753
        }
3754
    }
3755
}
클립보드 이미지 추가 (최대 크기: 500 MB)