프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ f9cc5190

이력 | 보기 | 이력해설 | 다운로드 (169 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> ZeroLengthSymbolToSymbolModelItemID = new List<string>();
43
        List<string> ZeroLengthModelItemID = new List<string>();
44
        List<string> ZeroLengthModelItemIDReverse = new List<string>();
45
        List<Symbol> prioritySymbols;
46

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

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

    
67
                }
68
            }
69
        }
70

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

    
83
                CreateDocument(ref drawingNumber, ref drawingName);
84

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

    
93
                    // Equipment Modeling
94
                    RunEquipmentModeling();
95
                    // Symbol Modeling
96
                    RunSymbolModeling();
97
                    // LineRun Line Modeling
98
                    RunLineModeling();
99
                    // Branch Line Modeling
100
                    RunBranchLineModeling();
101
                    // Clear Attribute
102
                    RunClearValueInconsistancy();
103
                    // EndBreak Modeling
104
                    RunEndBreakModeling();
105
                    // SpecBreak Modeling
106
                    RunSpecBreakModeling();
107
                    // Join SameConnector
108
                    RunJoinRunForSameConnector();
109
                    // Check FlowDirection
110
                    RunFlowDirection();
111
                    // Note Modeling
112
                    RunNoteModeling();
113
                    // Text Modeling
114
                    RunTextModeling();
115
                    // Input LineNumber Attribute
116
                    RunInputLineNumberAttribute();
117
                    // Input Symbol Attribute
118
                    RunInputSymbolAttribute();
119
                    // Input SpecBreak Attribute
120
                    RunInputSpecBreakAttribute();
121
                    // Label Symbol Modeling
122
                    RunLabelSymbolModeling();
123
                    
124

    
125
                    //// LineRun Line Join
126
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
127
                    //foreach (LineNumber lineNumber in document.LINENUMBERS)
128
                    //    try
129
                    //    {
130
                    //        foreach (LineRun run in lineNumber.RUNS)
131
                    //            JoinRunLine(run);
132
                    //    }
133
                    //    catch (Exception ex)
134
                    //    {
135
                    //        Log.Write("Error in JoinRunLine");
136
                    //        Log.Write("UID : " + lineNumber.UID);
137
                    //        Log.Write(ex.Message);
138
                    //        Log.Write(ex.StackTrace);
139
                    //    }
140

    
141
                    //// TrimLineRun Line Join
142
                    //foreach (TrimLine trimLine in document.TRIMLINES)
143
                    //    try
144
                    //    {
145
                    //        foreach (LineRun run in trimLine.RUNS)
146
                    //            JoinRunLine(run);
147
                    //    }
148
                    //    catch (Exception ex)
149
                    //    {
150
                    //        Log.Write("Error in JoinRunLine");
151
                    //        Log.Write("UID : " + trimLine.UID);
152
                    //        Log.Write(ex.Message);
153
                    //        Log.Write(ex.StackTrace);
154
                    //    }
155
                }
156
            }
157
            catch (Exception ex)
158
            {
159
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
160
                SplashScreenManager.CloseForm(false);
161
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
162
            }
163
            finally
164
            {
165
                Log.Write("End Modeling");
166
                application.ActiveWindow.Fit();
167

    
168
                if (currentDrawing != null)
169
                    ReleaseCOMObjects(currentDrawing);
170

    
171
                if (radApp.ActiveDocument != null)
172
                {
173
                    radApp.ActiveDocument.Save();
174
                    ReleaseCOMObjects(newDrawing);
175
                }
176

    
177
                ReleaseCOMObjects(dataSource);
178
                ReleaseCOMObjects(_placement);
179

    
180
                Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document);
181
                if (SplashScreenManager.Default.IsSplashFormVisible)
182
                {
183
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
184
                    SplashScreenManager.CloseForm(false);
185
                    Log.Write("\r\n");
186
                }
187
            }
188
        }
189
        private void RunEquipmentModeling()
190
        {
191
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
192
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
193
            foreach (Equipment item in document.Equipments)
194
            {
195
                try
196
                {
197
                    EquipmentModeling(item);
198
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
199
                }
200
                catch (Exception ex)
201
                {
202
                    Log.Write("Error in EquipmentModeling");
203
                    Log.Write("UID : " + item.UID);
204
                    Log.Write(ex.Message);
205
                    Log.Write(ex.StackTrace);
206
                }
207
            }
208
        }
209
        private void RunSymbolModeling()
210
        {
211
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
212
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
213
            prioritySymbols = GetPrioritySymbol();
214
            foreach (var item in prioritySymbols)
215
            {
216
                try
217
                {
218
                    SymbolModelingBySymbol(item);
219
                }
220
                catch (Exception ex)
221
                {
222
                    Log.Write("Error in SymbolModelingByPriority");
223
                    Log.Write("UID : " + item.UID);
224
                    Log.Write(ex.Message);
225
                    Log.Write(ex.StackTrace);
226
                }
227
            }
228
        }
229
        private void RunLineModeling()
230
        {
231
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
232
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
233
            SetPriorityLine();
234
            foreach (var item in document.LINES)
235
            {
236
                try
237
                {
238
                    NewLineModeling(item);
239
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
240
                }
241
                catch (Exception ex)
242
                {
243
                    Log.Write("Error in NewLineModeling");
244
                    Log.Write("UID : " + item.UID);
245
                    Log.Write(ex.Message);
246
                    Log.Write(ex.StackTrace);
247
                }
248
            }
249
        }
250
        private void RunBranchLineModeling()
251
        {
252
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, NewBranchLines.Count);
253
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
254
            int branchCount = NewBranchLines.Count;
255
            while (NewBranchLines.Count > 0)
256
            {
257
                Line item = NewBranchLines[0];
258
                try
259
                {
260
                    SortBranchLines();
261
                    NewLineModeling(item, true);
262
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
263
                }
264
                catch (Exception ex)
265
                {
266
                    Log.Write("Error in NewLineModeling");
267
                    Log.Write("UID : " + item.UID);
268
                    Log.Write(ex.Message);
269
                    Log.Write(ex.StackTrace);
270
                }
271
            }
272
        }
273
        private void RunClearValueInconsistancy()
274
        {
275
            int count = 1;
276
            bool loop = true;
277
            while (loop)
278
            {
279
                loop = false;
280
                LMAFilter filter = new LMAFilter();
281
                LMACriterion criterion = new LMACriterion();
282
                filter.ItemType = "Relationship";
283
                criterion.SourceAttributeName = "SP_DRAWINGID";
284
                criterion.Operator = "=";
285
                criterion.set_ValueAttribute(currentDrawing.Id);
286
                filter.get_Criteria().Add(criterion);
287

    
288
                LMRelationships relationships = new LMRelationships();
289
                relationships.Collect(dataSource, Filter: filter);
290

    
291
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count);
292
                if (count > 1)
293
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null);
294
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count);
295
                foreach (LMRelationship relationship in relationships)
296
                {
297
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
298
                    {
299
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
300
                        {
301
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
302
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
303
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
304
                            if (modelItem1 != null)
305
                            {
306
                                string attrName = array[0];
307
                                if (attrName.Contains("PipingPoint"))
308
                                {
309
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
310
                                    int index = Convert.ToInt32(relationship.get_Item1Location());
311
                                    LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
312
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
313
                                    {
314
                                        loop = true;
315
                                        attribute1.set_Value(DBNull.Value);
316
                                    }
317
                                }
318
                                else
319
                                {
320
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
321
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
322
                                    {
323
                                        loop = true;
324
                                        attribute1.set_Value(DBNull.Value);
325
                                    }
326
                                }
327
                                modelItem1.Commit();
328
                            }
329
                            if (modelItem2 != null)
330
                            {
331
                                string attrName = array[1];
332
                                if (attrName.Contains("PipingPoint"))
333
                                {
334
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
335
                                    int index = Convert.ToInt32(relationship.get_Item2Location());
336
                                    LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
337
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
338
                                    {
339
                                        attribute2.set_Value(DBNull.Value);
340
                                        loop = true;
341
                                    }
342
                                }
343
                                else
344
                                {
345
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
346
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
347
                                    {
348
                                        attribute2.set_Value(DBNull.Value);
349
                                        loop = true;
350
                                    }
351
                                }
352
                                modelItem2.Commit();
353
                            }
354
                            if (modelItem1 != null)
355
                                ReleaseCOMObjects(modelItem1);
356
                            if (modelItem2 != null)
357
                                ReleaseCOMObjects(modelItem2);
358
                            inconsistency.Commit();
359
                        }
360
                    }
361
                    relationship.Commit();
362
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
363
                }
364
                ReleaseCOMObjects(filter);
365
                ReleaseCOMObjects(criterion);
366
                ReleaseCOMObjects(relationships);
367
                count++;
368
            }
369
        }
370
        private void RunEndBreakModeling()
371
        {
372
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
373
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
374
            foreach (var item in document.EndBreaks)
375
                try
376
                {
377
                    EndBreakModeling(item);
378
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
379
                    if (string.IsNullOrEmpty(item.SPPID.RepresentationId))
380
                        Log.Write("Fail modeling endbreak UID : " + item.UID);
381
                }
382
                catch (Exception ex)
383
                {
384
                    Log.Write("Error in EndBreakModeling");
385
                    Log.Write("UID : " + item.UID);
386
                    Log.Write(ex.Message);
387
                    Log.Write(ex.StackTrace);
388
                }
389
        }
390
        private void RunSpecBreakModeling()
391
        {
392
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
393
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
394
            foreach (var item in document.SpecBreaks)
395
                try
396
                {
397
                    SpecBreakModeling(item);
398
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
399
                    if (string.IsNullOrEmpty(item.SPPID.RepresentationId))
400
                        Log.Write("Fail modeling specbreak UID : " + item.UID);
401
                }
402
                catch (Exception ex)
403
                {
404
                    Log.Write("Error in SpecBreakModeling");
405
                    Log.Write("UID : " + item.UID);
406
                    Log.Write(ex.Message);
407
                    Log.Write(ex.StackTrace);
408
                }
409
        }
410
        private void RunJoinRunForSameConnector()
411
        {
412
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
413
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join");
414
            foreach (var line in document.LINES)
415
            {
416
                if (!SPPIDUtil.IsSegmentLine(document, line))
417
                {
418
                    foreach (var connector in line.CONNECTORS)
419
                    {
420
                        if (connector.ConnectedObject != null &&
421
                            connector.ConnectedObject.GetType() == typeof(Line) &&
422
                            !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line)) 
423
                        {
424
                            Line connLine = connector.ConnectedObject as Line;
425
                            if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId)
426
                                JoinPipeRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId);
427
                        }
428
                    }
429
                }
430
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
431
            }
432
        }
433
        private void RunFlowDirection()
434
        {
435
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 
436
                document.LINES.Count + ZeroLengthModelItemID.Count + ZeroLengthModelItemIDReverse.Count + ZeroLengthSymbolToSymbolModelItemID.Count);
437
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Check Flow Direction");
438
            foreach (var line in document.LINES)
439
            {
440
                if (!string.IsNullOrEmpty(line.SPPID.ModelItemId))
441
                {
442
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
443
                    if (modelItem != null && modelItem.get_ItemStatus() == "Active")
444
                    {
445
                        LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
446
                        if (attribute != null)
447
                        {
448
                            attribute.set_Value("End 1 is upstream (Inlet)");
449
                            modelItem.Commit();
450
                        }
451

    
452
                        SetFlowDirectionByLine(line.SPPID.ModelItemId);
453

    
454
                        ReleaseCOMObjects(modelItem);
455
                    }
456
                }
457

    
458
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
459
            }
460
            foreach (var modelId in ZeroLengthModelItemID)
461
            {
462
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
463
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
464
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
465
                {
466
                    attribute.set_Value("End 1 is upstream (Inlet)");
467
                    zeroLengthModelItem.Commit();
468
                }
469

    
470
                SetFlowDirectionByLine(modelId);
471

    
472
                ReleaseCOMObjects(zeroLengthModelItem);
473
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
474
            }
475
            foreach (var modelId in ZeroLengthModelItemIDReverse)
476
            {
477
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
478
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
479
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
480
                {
481
                    attribute.set_Value("End 1 is downstream (Outlet)");
482
                    zeroLengthModelItem.Commit();
483
                }
484

    
485
                SetFlowDirectionByLine(modelId);
486

    
487
                ReleaseCOMObjects(zeroLengthModelItem);
488
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
489
            }
490
            foreach (var modelId in ZeroLengthSymbolToSymbolModelItemID)
491
            {
492
                SetFlowDirectionByLine(modelId);
493
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
494
            }
495

    
496
            void SetFlowDirectionByLine(string lineModelItemID)
497
            {
498
                LMModelItem modelItem = dataSource.GetModelItem(lineModelItemID);
499
                if (modelItem != null && modelItem.get_ItemStatus() == "Active")
500
                {
501
                    LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
502
                    if (attribute != null && !DBNull.Value.Equals(attribute.get_Value()))
503
                    {
504
                        string sFlowDirection = attribute.get_Value().ToString();
505
                        foreach (LMRepresentation rep in modelItem.Representations)
506
                        {
507
                            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
508
                            {
509
                                LMConnector connector = dataSource.GetConnector(rep.Id);
510

    
511
                                foreach (LMRelationship relationship in connector.Relation1Relationships)
512
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
513
                                foreach (LMRelationship relationship in connector.Relation2Relationships)
514
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
515

    
516
                                ReleaseCOMObjects(connector);
517
                            }
518
                        }
519
                    }
520
                    ReleaseCOMObjects(modelItem);
521
                }
522

    
523
                void SetSymbolFlowDirectionByRelationShip(LMRelationship relationship, LMConnector connector, string sFlowDirection)
524
                {
525
                    // Item2가 Symbol
526
                    if (!DBNull.Value.Equals(relationship.Item1RepresentationID) && relationship.Item1RepresentationID == connector.Id &&
527
                        relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.get_RepresentationType() == "Symbol")
528
                    {
529
                        int symbolIndex = Convert.ToInt32(relationship.get_Item2Location());
530
                        int lineIndex = Convert.ToInt32(relationship.get_Item1Location());
531
                        LMModelItem symbolModelItem = relationship.Item2RepresentationObject.ModelItemObject;
532

    
533
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
534

    
535
                        symbolModelItem.Commit();
536
                        ReleaseCOMObjects(symbolModelItem);
537
                    }
538
                    // Item1이 Symbol
539
                    else if (!DBNull.Value.Equals(relationship.Item2RepresentationID) && relationship.Item2RepresentationID == connector.Id &&
540
                            relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.get_RepresentationType() == "Symbol")
541
                    {
542
                        int symbolIndex = Convert.ToInt32(relationship.get_Item1Location());
543
                        int lineIndex = Convert.ToInt32(relationship.get_Item2Location());
544
                        LMModelItem symbolModelItem = relationship.Item1RepresentationObject.ModelItemObject;
545

    
546
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
547

    
548
                        symbolModelItem.Commit();
549
                        ReleaseCOMObjects(symbolModelItem);
550
                    }
551
                }
552

    
553
                void SetSymbolFlowDirection(int lineIndex, int symbolIndex, string sFlowDirection, LMModelItem symbolModelItem)
554
                {
555
                    string attrName = "PipingPoint" + symbolIndex + ".FlowDirection";
556
                    LMAAttribute attribute = symbolModelItem.Attributes[attrName];
557
                    if (attribute != null)
558
                    {
559
                        if (lineIndex == 0 && sFlowDirection == "End 1 is upstream (Inlet)")
560
                            attribute.set_Value("End 1 is downstream (Outlet)");
561
                        else if (lineIndex == 0 && sFlowDirection == "End 1 is downstream (Outlet)")
562
                            attribute.set_Value("End 1 is upstream (Inlet)");
563
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is upstream (Inlet)")
564
                            attribute.set_Value("End 1 is upstream (Inlet)");
565
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is downstream (Outlet)")
566
                            attribute.set_Value("End 1 is downstream (Outlet)");
567
                    }
568
                }
569
            }
570
        }
571
        private void RunNoteModeling()
572
        {
573
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
574
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
575
            foreach (var item in document.NOTES)
576
                try
577
                {
578
                    NoteModeling(item);
579
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
580
                }
581
                catch (Exception ex)
582
                {
583
                    Log.Write("Error in NoteModeling");
584
                    Log.Write("UID : " + item.UID);
585
                    Log.Write(ex.Message);
586
                    Log.Write(ex.StackTrace);
587
                }
588
        }
589
        private void RunTextModeling()
590
        {
591
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
592
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
593
            foreach (var item in document.TEXTINFOS)
594
                try
595
                {
596
                    TextModeling(item);
597
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
598
                }
599
                catch (Exception ex)
600
                {
601
                    Log.Write("Error in TextModeling");
602
                    Log.Write("UID : " + item.UID);
603
                    Log.Write(ex.Message);
604
                    Log.Write(ex.StackTrace);
605
                }
606
        }
607
        private void RunInputLineNumberAttribute()
608
        {
609
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
610
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
611
            foreach (var item in document.LINENUMBERS)
612
                try
613
                {
614
                    InputLineNumberAttribute(item);
615
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
616
                }
617
                catch (Exception ex)
618
                {
619
                    Log.Write("Error in InputLineNumberAttribute");
620
                    Log.Write("UID : " + item.UID);
621
                    Log.Write(ex.Message);
622
                    Log.Write(ex.StackTrace);
623
                }
624
        }
625
        private void RunInputSymbolAttribute()
626
        {
627
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
628
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
629
            foreach (var item in document.SYMBOLS)
630
                try
631
                {
632
                    InputSymbolAttribute(item, item.ATTRIBUTES);
633
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
634
                }
635
                catch (Exception ex)
636
                {
637
                    Log.Write("Error in InputSymbolAttribute");
638
                    Log.Write("UID : " + item.UID);
639
                    Log.Write(ex.Message);
640
                    Log.Write(ex.StackTrace);
641
                }
642
        }
643
        private void RunInputSpecBreakAttribute()
644
        {
645
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
646
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
647
            foreach (var item in document.SpecBreaks)
648
                try
649
                {
650
                    InputSpecBreakAttribute(item);
651
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
652
                }
653
                catch (Exception ex)
654
                {
655
                    Log.Write("Error in InputSpecBreakAttribute");
656
                    Log.Write("UID : " + item.UID);
657
                    Log.Write(ex.Message);
658
                    Log.Write(ex.StackTrace);
659
                }
660
        }
661
        private void RunLabelSymbolModeling()
662
        {
663
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
664
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
665
            foreach (var item in document.SYMBOLS)
666
                try
667
                {
668
                    LabelSymbolModeling(item);
669
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
670
                }
671
                catch (Exception ex)
672
                {
673
                    Log.Write("Error in LabelSymbolModeling");
674
                    Log.Write("UID : " + item.UID);
675
                    Log.Write(ex.Message);
676
                    Log.Write(ex.StackTrace);
677
                }
678
        }
679

    
680
        /// <summary>
681
        /// 도면 생성 메서드
682
        /// </summary>
683
        private void CreateDocument(ref string drawingNumber, ref string drawingName)
684
        {
685
            Log.Write("------------------ Start create document ------------------");
686
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
687
            Log.Write("Drawing name : " + drawingName);
688
            Log.Write("Drawing number : " + drawingNumber);
689
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
690
            document.SPPID_DrawingNumber = drawingNumber;
691
            document.SPPID_DrawingName = drawingName;
692
            application.ActiveWindow.Fit();
693
            Thread.Sleep(1000);
694
            application.ActiveWindow.Zoom = 2000;
695
            Thread.Sleep(2000);
696

    
697
            //current LMDrawing 가져오기
698
            LMAFilter filter = new LMAFilter();
699
            LMACriterion criterion = new LMACriterion();
700
            filter.ItemType = "Drawing";
701
            criterion.SourceAttributeName = "Name";
702
            criterion.Operator = "=";
703
            criterion.set_ValueAttribute(drawingName);
704
            filter.get_Criteria().Add(criterion);
705

    
706
            LMDrawings drawings = new LMDrawings();
707
            drawings.Collect(dataSource, Filter: filter);
708

    
709
            currentDrawing = ((dynamic)drawings).Nth(1);
710
        }
711

    
712
        /// <summary>
713
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
714
        /// </summary>
715
        /// <param name="drawingName"></param>
716
        /// <param name="drawingNumber"></param>
717
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
718
        {
719
            LMDrawings drawings = new LMDrawings();
720
            drawings.Collect(dataSource);
721

    
722
            List<string> drawingNameList = new List<string>();
723
            List<string> drawingNumberList = new List<string>();
724

    
725
            foreach (LMDrawing item in drawings)
726
            {
727
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
728
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
729
            }
730

    
731
            int nameLength = drawingName.Length;
732
            while (drawingNameList.Contains(drawingName))
733
            {
734
                if (nameLength == drawingName.Length)
735
                    drawingName += "-1";
736
                else
737
                {
738
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
739
                    drawingName = drawingName.Substring(0, nameLength + 1);
740
                    drawingName += ++index;
741
                }
742
            }
743

    
744
            int numberLength = drawingNumber.Length;
745
            while (drawingNameList.Contains(drawingNumber))
746
            {
747
                if (numberLength == drawingNumber.Length)
748
                    drawingNumber += "-1";
749
                else
750
                {
751
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
752
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
753
                    drawingNumber += ++index;
754
                }
755
            }
756

    
757
            ReleaseCOMObjects(drawings);
758
        }
759

    
760
        /// <summary>
761
        /// 도면 크기 구하는 메서드
762
        /// </summary>
763
        /// <returns></returns>
764
        private bool DocumentCoordinateCorrection()
765
        {
766
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
767
            {
768
                Log.Write("Setting Drawing X, Drawing Y");
769
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
770
                Log.Write("Start coordinate correction");
771
                document.CoordinateCorrection();
772
                return true;
773
            }
774
            else
775
            {
776
                Log.Write("Need Drawing X, Y");
777
                return false;
778
            }
779
        }
780

    
781
        /// <summary>
782
        /// 심볼을 실제로 Modeling 메서드
783
        /// </summary>
784
        /// <param name="symbol"></param>
785
        /// <param name="targetSymbol"></param>
786
        /// <param name="prevSymbol"></param>
787
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
788
        {
789
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
790
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
791
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
792
                return;
793
            // 이미 모델링 됐을 경우
794
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
795
                return;
796

    
797
            LMSymbol _LMSymbol = null;
798

    
799
            string mappingPath = symbol.SPPID.MAPPINGNAME;
800
            double x = symbol.SPPID.ORIGINAL_X;
801
            double y = symbol.SPPID.ORIGINAL_Y;
802
            int mirror = 0;
803
            double angle = symbol.ANGLE;
804

    
805
            // OPC 일경우 180도 일때 Mirror
806
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
807
                mirror = 1;
808

    
809
            // Mirror 계산
810
            if (symbol.FLIP == 1)
811
            {
812
                mirror = 1;
813
                angle += Math.PI;
814
            }
815

    
816
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
817
            {
818
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
819
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
820
                if (connector != null)
821
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
822

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

    
825
                if (_LMSymbol != null && _TargetItem != null)
826
                {
827
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
828

    
829
                    if (SPPIDUtil.IsSegmentLine(document, symbol, targetSymbol))
830
                    {
831
                        LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
832
                        if (reModelingConnector != null)
833
                            ReModelingLMConnector(reModelingConnector);
834
                    }
835
                }
836

    
837
                ReleaseCOMObjects(_TargetItem);
838
            }
839
            else
840
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
841

    
842
            if (_LMSymbol != null)
843
            {
844
                _LMSymbol.Commit();
845
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
846
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
847
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
848

    
849
                foreach (var item in symbol.ChildSymbols)
850
                    CreateChildSymbol(item, _LMSymbol);
851

    
852
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
853
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
854

    
855
                double[] range = null;
856
                GetSPPIDSymbolRange(symbol, ref range);
857
                symbol.SPPID.SPPID_Min_X = range[0];
858
                symbol.SPPID.SPPID_Min_Y = range[1];
859
                symbol.SPPID.SPPID_Max_X = range[2];
860
                symbol.SPPID.SPPID_Max_Y = range[3];
861

    
862
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
863
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
864
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
865
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
866

    
867
                ReleaseCOMObjects(_LMSymbol);
868
            }
869
        }
870

    
871
        private void RemoveSymbol(Symbol symbol)
872
        {
873
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
874
            {
875
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
876
                if (_LMSymbol != null)
877
                {
878
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
879
                    ReleaseCOMObjects(_LMSymbol);
880
                }
881
            }
882

    
883
            symbol.SPPID.RepresentationId = string.Empty;
884
            symbol.SPPID.ModelItemID = string.Empty;
885
            symbol.SPPID.SPPID_X = double.NaN;
886
            symbol.SPPID.SPPID_Y = double.NaN;
887
            symbol.SPPID.SPPID_Min_X = double.NaN;
888
            symbol.SPPID.SPPID_Min_Y = double.NaN;
889
            symbol.SPPID.SPPID_Max_X = double.NaN;
890
            symbol.SPPID.SPPID_Max_Y = double.NaN;
891
        }
892

    
893
        private void RemoveSymbol(List<Symbol> symbols)
894
        {
895
            foreach (var symbol in symbols)
896
            {
897
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
898
                {
899
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
900
                    if (_LMSymbol != null)
901
                    {
902
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
903
                        ReleaseCOMObjects(_LMSymbol);
904
                    }
905
                }
906

    
907
                symbol.SPPID.RepresentationId = string.Empty;
908
                symbol.SPPID.ModelItemID = string.Empty;
909
                symbol.SPPID.SPPID_X = double.NaN;
910
                symbol.SPPID.SPPID_Y = double.NaN;
911
                symbol.SPPID.SPPID_Min_X = double.NaN;
912
                symbol.SPPID.SPPID_Min_Y = double.NaN;
913
                symbol.SPPID.SPPID_Max_X = double.NaN;
914
                symbol.SPPID.SPPID_Max_Y = double.NaN;
915
            }
916
        }
917

    
918
        /// <summary>
919
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
920
        /// </summary>
921
        /// <param name="targetConnector"></param>
922
        /// <param name="targetSymbol"></param>
923
        /// <param name="x"></param>
924
        /// <param name="y"></param>
925
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
926
        {
927
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
928

    
929
            double[] range = null;
930
            List<double[]> points = new List<double[]>();
931
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
932
            double x1 = range[0];
933
            double y1 = range[1];
934
            double x2 = range[2];
935
            double y2 = range[3];
936

    
937
            // Origin 기준 Connector의 위치차이
938
            double sceneX = 0;
939
            double sceneY = 0;
940
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
941
            double originX = 0;
942
            double originY = 0;
943
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
944
            double gapX = originX - sceneX;
945
            double gapY = originY - sceneY;
946

    
947
            // SPPID Symbol과 ID2 심볼의 크기 차이
948
            double sizeWidth = 0;
949
            double sizeHeight = 0;
950
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
951
            if (sizeWidth == 0 || sizeHeight == 0)
952
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
953

    
954
            double percentX = (x2 - x1) / sizeWidth;
955
            double percentY = (y2 - y1) / sizeHeight;
956

    
957
            double SPPIDgapX = gapX * percentX;
958
            double SPPIDgapY = gapY * percentY;
959

    
960
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
961
            double distance = double.MaxValue;
962
            double[] resultPoint;
963
            foreach (var point in points)
964
            {
965
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
966
                if (distance > result)
967
                {
968
                    distance = result;
969
                    resultPoint = point;
970
                    x = point[0];
971
                    y = point[1];
972
                }
973
            }
974

    
975
            ReleaseCOMObjects(_TargetItem);
976
        }
977

    
978
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
979
        {
980
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
981
            if (index == 0)
982
            {
983
                x = targetLine.SPPID.START_X;
984
                y = targetLine.SPPID.START_Y;
985
            }
986
            else
987
            {
988
                x = targetLine.SPPID.END_X;
989
                y = targetLine.SPPID.END_Y;
990
            }
991
        }
992

    
993
        /// <summary>
994
        /// SPPID Symbol의 Range를 구한다.
995
        /// </summary>
996
        /// <param name="symbol"></param>
997
        /// <param name="range"></param>
998
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
999
        {
1000
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1001
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1002
            double x1 = 0;
1003
            double y1 = 0;
1004
            double x2 = 0;
1005
            double y2 = 0;
1006
            symbol2d.Range(out x1, out y1, out x2, out y2);
1007
            range = new double[] { x1, y1, x2, y2 };
1008

    
1009
            for (int i = 1; i < int.MaxValue; i++)
1010
            {
1011
                double connX = 0;
1012
                double connY = 0;
1013
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
1014
                    points.Add(new double[] { connX, connY });
1015
                else
1016
                    break;
1017
            }
1018

    
1019
            foreach (var childSymbol in symbol.ChildSymbols)
1020
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1021

    
1022
            ReleaseCOMObjects(_TargetItem);
1023
        }
1024

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

    
1036
            foreach (var childSymbol in symbol.ChildSymbols)
1037
                GetSPPIDChildSymbolRange(childSymbol, ref range);
1038

    
1039
            ReleaseCOMObjects(_TargetItem);
1040
        }
1041

    
1042
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1043
        {
1044
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1045
            foreach (var symbol in symbols)
1046
            {
1047
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1048
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1049
                double x1 = 0;
1050
                double y1 = 0;
1051
                double x2 = 0;
1052
                double y2 = 0;
1053
                symbol2d.Range(out x1, out y1, out x2, out y2);
1054

    
1055
                tempRange[0] = Math.Min(tempRange[0], x1);
1056
                tempRange[1] = Math.Min(tempRange[1], y1);
1057
                tempRange[2] = Math.Max(tempRange[2], x2);
1058
                tempRange[3] = Math.Max(tempRange[3], y2);
1059

    
1060
                foreach (var childSymbol in symbol.ChildSymbols)
1061
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1062

    
1063
                ReleaseCOMObjects(_TargetItem);
1064
            }
1065

    
1066
            range = tempRange;
1067
        }
1068

    
1069
        /// <summary>
1070
        /// Child Modeling 된 Symbol의 Range를 구한다.
1071
        /// </summary>
1072
        /// <param name="childSymbol"></param>
1073
        /// <param name="range"></param>
1074
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1075
        {
1076
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1077
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1078
            double x1 = 0;
1079
            double y1 = 0;
1080
            double x2 = 0;
1081
            double y2 = 0;
1082
            symbol2d.Range(out x1, out y1, out x2, out y2);
1083
            range[0] = Math.Min(range[0], x1);
1084
            range[1] = Math.Min(range[1], y1);
1085
            range[2] = Math.Max(range[2], x2);
1086
            range[3] = Math.Max(range[3], y2);
1087

    
1088
            for (int i = 1; i < int.MaxValue; i++)
1089
            {
1090
                double connX = 0;
1091
                double connY = 0;
1092
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1093
                    points.Add(new double[] { connX, connY });
1094
                else
1095
                    break;
1096
            }
1097

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

    
1101
            ReleaseCOMObjects(_ChildSymbol);
1102
        }
1103

    
1104
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1105
        {
1106
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1107
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1108
            double x1 = 0;
1109
            double y1 = 0;
1110
            double x2 = 0;
1111
            double y2 = 0;
1112
            symbol2d.Range(out x1, out y1, out x2, out y2);
1113
            range[0] = Math.Min(range[0], x1);
1114
            range[1] = Math.Min(range[1], y1);
1115
            range[2] = Math.Max(range[2], x2);
1116
            range[3] = Math.Max(range[3], y2);
1117

    
1118
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1119
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1120

    
1121
            ReleaseCOMObjects(_ChildSymbol);
1122
        }
1123

    
1124
        /// <summary>
1125
        /// Label Symbol Modeling
1126
        /// </summary>
1127
        /// <param name="symbol"></param>
1128
        private void LabelSymbolModeling(Symbol symbol)
1129
        {
1130
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1131
            {
1132
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1133
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1134
                    return;
1135
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1136

    
1137
                string symbolUID = itemAttribute.VALUE;
1138
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1139
                if (targetItem != null &&
1140
                    (targetItem.GetType() == typeof(Symbol) ||
1141
                    targetItem.GetType() == typeof(Equipment)))
1142
                {
1143
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1144
                    string sRep = null;
1145
                    if (targetItem.GetType() == typeof(Symbol))
1146
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1147
                    else if (targetItem.GetType() == typeof(Equipment))
1148
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1149
                    if (!string.IsNullOrEmpty(sRep))
1150
                    {
1151
                        // LEADER Line 검사
1152
                        bool leaderLine = false;
1153
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1154
                        if (symbolMapping != null)
1155
                            leaderLine = symbolMapping.LEADERLINE;
1156

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

    
1161
                        //Leader 선 센터로
1162
                        if (_LMLabelPresist != null)
1163
                        {
1164
                            // Target Item에 Label의 Attribute Input
1165
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1166

    
1167
                            string OID = _LMLabelPresist.get_GraphicOID().ToString();
1168
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1169
                            if (dependency != null)
1170
                            {
1171
                                bool result = false;
1172
                                foreach (var attributes in dependency.AttributeSets)
1173
                                {
1174
                                    foreach (var attribute in attributes)
1175
                                    {
1176
                                        string name = attribute.Name;
1177
                                        string value = attribute.GetValue().ToString();
1178
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1179
                                        {
1180
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1181
                                            {
1182
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1183
                                                {
1184
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1185
                                                    double prevX = _TargetItem.get_XCoordinate();
1186
                                                    double prevY = _TargetItem.get_YCoordinate();
1187
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1188
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1189
                                                    result = true;
1190
                                                    break;
1191
                                                }
1192
                                            }
1193
                                        }
1194

    
1195
                                        if (result)
1196
                                            break;
1197
                                    }
1198

    
1199
                                    if (result)
1200
                                        break;
1201
                                }
1202
                            }
1203

    
1204
                            _LMLabelPresist.Commit();
1205
                            ReleaseCOMObjects(_LMLabelPresist);
1206
                        }
1207

    
1208
                        ReleaseCOMObjects(_TargetItem);
1209
                    }
1210
                }
1211
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1212
                {
1213
                    Line targetLine = targetItem as Line;
1214
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1215
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1216
                    if (connectedLMConnector != null)
1217
                    {
1218
                        // LEADER Line 검사
1219
                        bool leaderLine = false;
1220
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1221
                        if (symbolMapping != null)
1222
                            leaderLine = symbolMapping.LEADERLINE;
1223

    
1224
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1225
                        if (_LMLabelPresist != null)
1226
                        {
1227
                            _LMLabelPresist.Commit();
1228
                            ReleaseCOMObjects(_LMLabelPresist);
1229
                        }
1230
                        ReleaseCOMObjects(connectedLMConnector);
1231
                    }
1232

    
1233
                    foreach (var item in connectorVertices)
1234
                        if (item.Key != null)
1235
                            ReleaseCOMObjects(item.Key);
1236
                }
1237
            }
1238
        }
1239

    
1240
        /// <summary>
1241
        /// Equipment를 실제로 Modeling 메서드
1242
        /// </summary>
1243
        /// <param name="equipment"></param>
1244
        private void EquipmentModeling(Equipment equipment)
1245
        {
1246
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1247
                return;
1248

    
1249
            LMSymbol _LMSymbol = null;
1250
            LMSymbol targetItem = null;
1251
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1252
            double x = equipment.SPPID.ORIGINAL_X;
1253
            double y = equipment.SPPID.ORIGINAL_Y;
1254
            int mirror = 0;
1255
            double angle = equipment.ANGLE;
1256

    
1257
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1258

    
1259
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1260
            if (connector != null)
1261
            {
1262
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1263
                if (connEquipment != null)
1264
                {
1265
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1266
                        EquipmentModeling(connEquipment);
1267

    
1268
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1269
                    {
1270
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1271
                        if (targetItem != null)
1272
                        {
1273
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1274
                        }
1275
                        else
1276
                        {
1277
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1278
                        }
1279
                    }
1280
                    else
1281
                    {
1282
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1283
                    }
1284
                }
1285
                else
1286
                {
1287
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1288
                }
1289
            }
1290
            else
1291
            {
1292
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1293
            }
1294

    
1295
            if (_LMSymbol != null)
1296
            {
1297
                _LMSymbol.Commit();
1298
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1299
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1300
                ReleaseCOMObjects(_LMSymbol);
1301
            }
1302

    
1303
            if (targetItem != null)
1304
            {
1305
                ReleaseCOMObjects(targetItem);
1306
            }
1307

    
1308
            ReleaseCOMObjects(_LMSymbol);
1309
        }
1310

    
1311
        /// <summary>
1312
        /// 첫 진입점
1313
        /// </summary>
1314
        /// <param name="symbol"></param>
1315
        private void SymbolModelingBySymbol(Symbol symbol)
1316
        {
1317
            SymbolModeling(symbol, null);
1318
            List<object> endObjects = new List<object>();
1319
            endObjects.Add(symbol);
1320

    
1321
            foreach (var connector in symbol.CONNECTORS)
1322
            {
1323
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1324
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1325
                {
1326
                    endObjects.Add(connItem);
1327
                    if (connItem.GetType() == typeof(Symbol))
1328
                    {
1329
                        Symbol connSymbol = connItem as Symbol;
1330
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1331
                        {
1332
                            SymbolModeling(connSymbol, symbol);
1333
                        }
1334
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1335
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1336
                    }
1337
                    else if (connItem.GetType() == typeof(Line))
1338
                    {
1339
                        Line connLine = connItem as Line;
1340
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1341
                    }
1342
                }
1343
            }
1344
        }
1345

    
1346
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1347
        {
1348
            foreach (var connector in symbol.CONNECTORS)
1349
            {
1350
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1351
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1352
                {
1353
                    if (!endObjects.Contains(connItem))
1354
                    {
1355
                        endObjects.Add(connItem);
1356
                        if (connItem.GetType() == typeof(Symbol))
1357
                        {
1358
                            Symbol connSymbol = connItem as Symbol;
1359
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1360
                            {
1361
                                SymbolModeling(connSymbol, symbol);
1362
                            }
1363
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1364
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1365
                        }
1366
                        else if (connItem.GetType() == typeof(Line))
1367
                        {
1368
                            Line connLine = connItem as Line;
1369
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1370
                        }
1371
                    }
1372
                }
1373
            }
1374
        }
1375

    
1376
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1377
        {
1378
            foreach (var connector in line.CONNECTORS)
1379
            {
1380
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1381
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1382
                {
1383
                    if (!endObjects.Contains(connItem))
1384
                    {
1385
                        endObjects.Add(connItem);
1386
                        if (connItem.GetType() == typeof(Symbol))
1387
                        {
1388
                            Symbol connSymbol = connItem as Symbol;
1389
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1390
                            {
1391
                                List<Symbol> group = new List<Symbol>();
1392
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1393
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1394
                                List<Symbol> endModelingGroup = new List<Symbol>();
1395
                                if (priority != null)
1396
                                {
1397
                                    SymbolGroupModeling(priority, group);
1398

    
1399
                                    // Range 겹치는지 확인해야함
1400
                                    double[] prevRange = null;
1401
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1402
                                    double[] groupRange = null;
1403
                                    GetSPPIDSymbolRange(group, ref groupRange);
1404

    
1405
                                    double distanceX = 0;
1406
                                    double distanceY = 0;
1407
                                    bool overlapX = false;
1408
                                    bool overlapY = false;
1409
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1410
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1411
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1412
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1413
                                    {
1414
                                        RemoveSymbol(group);
1415
                                        foreach (var _temp in group)
1416
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1417

    
1418
                                        SymbolGroupModeling(priority, group);
1419
                                    }
1420
                                }
1421
                                else
1422
                                {
1423
                                    SymbolModeling(connSymbol, null);
1424
                                    // Range 겹치는지 확인해야함
1425
                                    double[] prevRange = null;
1426
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1427
                                    double[] connRange = null;
1428
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1429

    
1430
                                    double distanceX = 0;
1431
                                    double distanceY = 0;
1432
                                    bool overlapX = false;
1433
                                    bool overlapY = false;
1434
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1435
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1436
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1437
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1438
                                    {
1439
                                        RemoveSymbol(connSymbol);
1440
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1441

    
1442
                                        SymbolModeling(connSymbol, null);
1443
                                    }
1444
                                }
1445
                            }
1446
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1447
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1448
                        }
1449
                        else if (connItem.GetType() == typeof(Line))
1450
                        {
1451
                            Line connLine = connItem as Line;
1452
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1453
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1454
                        }
1455
                    }
1456
                }
1457
            }
1458
        }
1459

    
1460
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1461
        {
1462
            List<Symbol> endModelingGroup = new List<Symbol>();
1463
            SymbolModeling(firstSymbol, null);
1464
            endModelingGroup.Add(firstSymbol);
1465
            while (endModelingGroup.Count != group.Count)
1466
            {
1467
                foreach (var _symbol in group)
1468
                {
1469
                    if (!endModelingGroup.Contains(_symbol))
1470
                    {
1471
                        foreach (var _connector in _symbol.CONNECTORS)
1472
                        {
1473
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
1474
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
1475
                            {
1476
                                SymbolModeling(_symbol, _connSymbol);
1477
                                endModelingGroup.Add(_symbol);
1478
                                break;
1479
                            }
1480
                        }
1481
                    }
1482
                }
1483
            }
1484
        }
1485

    
1486
        /// <summary>
1487
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
1488
        /// </summary>
1489
        /// <param name="childSymbol"></param>
1490
        /// <param name="parentSymbol"></param>
1491
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
1492
        {
1493
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
1494
            double x1 = 0;
1495
            double x2 = 0;
1496
            double y1 = 0;
1497
            double y2 = 0;
1498
            symbol2d.Range(out x1, out y1, out x2, out y2);
1499

    
1500
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1501
            if (_LMSymbol != null)
1502
            {
1503
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1504
                foreach (var item in childSymbol.ChildSymbols)
1505
                    CreateChildSymbol(item, _LMSymbol);
1506
            }
1507

    
1508

    
1509
            ReleaseCOMObjects(_LMSymbol);
1510
        }
1511

    
1512
        private void NewLineModeling(Line line, bool isBranchModeling = false)
1513
        {
1514
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (NewBranchLines.Contains(line) && !isBranchModeling))
1515
                return;
1516

    
1517
            List<Line> group = new List<Line>();
1518
            GetConnectedLineGroup(line, group);
1519
            LineCoordinateCorrection(group);
1520

    
1521
            foreach (var groupLine in group)
1522
            {
1523
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1524
                {
1525
                    NewBranchLines.Add(groupLine);
1526
                    continue;
1527
                }
1528

    
1529
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
1530
                LMSymbol _LMSymbolStart = null;
1531
                LMSymbol _LMSymbolEnd = null;
1532
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1533
                foreach (var connector in groupLine.CONNECTORS)
1534
                {
1535
                    double x = 0;
1536
                    double y = 0;
1537
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
1538
                    if (connector.ConnectedObject == null)
1539
                    {
1540
                        placeRunInputs.AddPoint(x, y);
1541
                    }
1542
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
1543
                    {
1544
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
1545
                        GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y);
1546
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1547
                        {
1548
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
1549
                            placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y);
1550
                        }
1551
                        else
1552
                        {
1553
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
1554
                            placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y);
1555
                        }
1556
                    }
1557
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
1558
                    {
1559
                        Line targetLine = connector.ConnectedObject as Line;
1560
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
1561
                        {
1562
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
1563
                            placeRunInputs.AddConnectorTarget(targetConnector, x, y);
1564
                            ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1565
                        }
1566
                        else
1567
                        {
1568
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1569
                            {
1570
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1571
                                    placeRunInputs.AddPoint(x, -0.1);
1572
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1573
                                    placeRunInputs.AddPoint(-0.1, y);
1574
                                else
1575
                                    placeRunInputs.AddPoint(x, -0.1);
1576
                            }
1577

    
1578
                            placeRunInputs.AddPoint(x, y);
1579

    
1580
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1581
                            {
1582
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1583
                                    placeRunInputs.AddPoint(x, -0.1);
1584
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1585
                                    placeRunInputs.AddPoint(-0.1, y);
1586
                                else
1587
                                    placeRunInputs.AddPoint(x, -0.1);
1588
                            }
1589
                        }
1590
                    }
1591
                }
1592

    
1593
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1594
                if (_lMConnector != null)
1595
                {
1596
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1597
                    bool bRemodelingStart = false;
1598
                    if (_LMSymbolStart != null)
1599
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1600
                    bool bRemodelingEnd = false;
1601
                    if (_LMSymbolEnd != null)
1602
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1603

    
1604
                    if (bRemodelingStart || bRemodelingEnd)
1605
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1606

    
1607
                    FlowMarkModeling(groupLine);
1608
                    LineNumberModeling(groupLine);
1609

    
1610
                    ReleaseCOMObjects(_lMConnector);
1611
                }
1612

    
1613
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1614
                x.ConnectedObject != null &&
1615
                x.ConnectedObject.GetType() == typeof(Line) &&
1616
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1617
                .Select(x => x.ConnectedObject)
1618
                .ToList();
1619

    
1620
                foreach (var item in removeLines)
1621
                    RemoveLineForModeling(item as Line);
1622

    
1623
                if (_LMAItem != null)
1624
                    ReleaseCOMObjects(_LMAItem);
1625
                if (placeRunInputs != null)
1626
                    ReleaseCOMObjects(placeRunInputs);
1627
                if (_LMSymbolStart != null)
1628
                    ReleaseCOMObjects(_LMSymbolStart);
1629
                if (_LMSymbolEnd != null)
1630
                    ReleaseCOMObjects(_LMSymbolEnd);
1631

    
1632
                if (isBranchModeling && NewBranchLines.Contains(groupLine))
1633
                    NewBranchLines.Remove(groupLine);
1634
            }
1635
        }
1636

    
1637
        private void RemoveLineForModeling(Line line)
1638
        {
1639
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1640
            if (modelItem != null)
1641
            {
1642
                foreach (LMRepresentation rep in modelItem.Representations)
1643
                {
1644
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1645
                    {
1646
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1647
                        dynamic OID = rep.get_GraphicOID().ToString();
1648
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1649
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1650
                        int verticesCount = lineStringGeometry.VertexCount;
1651
                        double[] vertices = null;
1652
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1653
                        for (int i = 0; i < verticesCount; i++)
1654
                        {
1655
                            double x = 0;
1656
                            double y = 0;
1657
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1658
                            if (verticesCount == 2 && x < 0 || y < 0)
1659
                                _placement.PIDRemovePlacement(rep);
1660
                        }
1661
                        ReleaseCOMObjects(_LMConnector);
1662
                    }
1663
                }
1664

    
1665
                ReleaseCOMObjects(modelItem);
1666
            }
1667
        }
1668

    
1669
        private void GetConnectedLineGroup(Line line, List<Line> group)
1670
        {
1671
            if (!group.Contains(line))
1672
                group.Add(line);
1673
            foreach (var connector in line.CONNECTORS)
1674
            {
1675
                if (connector.ConnectedObject != null &&
1676
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1677
                    !group.Contains(connector.ConnectedObject) &&
1678
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
1679
                {
1680
                    Line connLine = connector.ConnectedObject as Line;
1681
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
1682
                        GetConnectedLineGroup(connLine, group);
1683
                }
1684
            }
1685
        }
1686

    
1687
        private void LineCoordinateCorrection(List<Line> group)
1688
        {
1689
            // 순서대로 전 Item 기준 정렬
1690
            LineCoordinateCorrectionByStart(group);
1691

    
1692
            // 역으로 심볼이 있을 경우 좌표 보정
1693
            LineCoordinateCorrectionForLastLine(group);
1694
        }
1695

    
1696
        private void LineCoordinateCorrectionByStart(List<Line> group)
1697
        {
1698
            for (int i = 0; i < group.Count; i++)
1699
            {
1700
                Line line = group[i];
1701
                if (i == 0)
1702
                {
1703
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1704
                    if (symbolConnector != null)
1705
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
1706
                }
1707
                else if (i != 0)
1708
                {
1709
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
1710
                }
1711
            }
1712
        }
1713

    
1714
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
1715
        {
1716
            Line checkLine = group[group.Count - 1];
1717
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1718
            if (lastSymbolConnector != null)
1719
            {
1720
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
1721
                for (int i = group.Count - 2; i >= 0; i--)
1722
                {
1723
                    Line line = group[i + 1];
1724
                    Line prevLine = group[i];
1725

    
1726
                    // 같으면 보정
1727
                    if (line.SlopeType == prevLine.SlopeType)
1728
                        LineCoordinateCorrectionByConnItem(prevLine, line);
1729
                    else
1730
                    {
1731
                        if (line.SlopeType == SlopeType.HORIZONTAL)
1732
                        {
1733
                            double prevX = 0;
1734
                            double prevY = 0;
1735
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1736
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
1737

    
1738
                            double x = 0;
1739
                            double y = 0;
1740
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1741
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
1742
                        }
1743
                        else if (line.SlopeType == SlopeType.VERTICAL)
1744
                        {
1745
                            double prevX = 0;
1746
                            double prevY = 0;
1747
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1748
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
1749

    
1750
                            double x = 0;
1751
                            double y = 0;
1752
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1753
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
1754
                        }
1755
                        break;
1756
                    }
1757
                }
1758
            }
1759
        }
1760

    
1761
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
1762
        {
1763
            double x = 0;
1764
            double y = 0;
1765
            if (connItem.GetType() == typeof(Symbol))
1766
            {
1767
                Symbol targetSymbol = connItem as Symbol;
1768
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
1769
                if (targetConnector != null)
1770
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
1771
                else
1772
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
1773
            }
1774
            else if (connItem.GetType() == typeof(Line))
1775
            {
1776
                Line targetLine = connItem as Line;
1777
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
1778
            }
1779

    
1780
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
1781
        }
1782

    
1783
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
1784
        {
1785
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1786
            int index = line.CONNECTORS.IndexOf(connector);
1787
            if (index == 0)
1788
            {
1789
                line.SPPID.START_X = x;
1790
                line.SPPID.START_Y = y;
1791
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1792
                    line.SPPID.END_Y = y;
1793
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1794
                    line.SPPID.END_X = x;
1795
            }
1796
            else
1797
            {
1798
                line.SPPID.END_X = x;
1799
                line.SPPID.END_Y = y;
1800
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1801
                    line.SPPID.START_Y = y;
1802
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1803
                    line.SPPID.START_X = x;
1804
            }
1805
        }
1806

    
1807
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
1808
        {
1809
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1810
            int index = line.CONNECTORS.IndexOf(connector);
1811
            if (index == 0)
1812
            {
1813
                line.SPPID.START_X = x;
1814
                if (line.SlopeType == SlopeType.VERTICAL)
1815
                    line.SPPID.END_X = x;
1816
            }
1817
            else
1818
            {
1819
                line.SPPID.END_X = x;
1820
                if (line.SlopeType == SlopeType.VERTICAL)
1821
                    line.SPPID.START_X = x;
1822
            }
1823
        }
1824

    
1825
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
1826
        {
1827
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1828
            int index = line.CONNECTORS.IndexOf(connector);
1829
            if (index == 0)
1830
            {
1831
                line.SPPID.START_Y = y;
1832
                if (line.SlopeType == SlopeType.HORIZONTAL)
1833
                    line.SPPID.END_Y = y;
1834
            }
1835
            else
1836
            {
1837
                line.SPPID.END_Y = y;
1838
                if (line.SlopeType == SlopeType.HORIZONTAL)
1839
                    line.SPPID.START_Y = y;
1840
            }
1841
        }
1842

    
1843
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1844
        {
1845
            if (symbol != null)
1846
            {
1847
                string repID = symbol.AsLMRepresentation().Id;
1848
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1849
                string lineUID = line.UID;
1850

    
1851
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1852
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1853
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1854

    
1855
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
1856
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1857
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1858

    
1859
                if (startSpecBreak != null || startEndBreak != null)
1860
                    result = true;
1861
            }
1862
        }
1863

    
1864
        /// <summary>
1865
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1866
        /// </summary>
1867
        /// <param name="lines"></param>
1868
        /// <param name="prevLMConnector"></param>
1869
        /// <param name="startSymbol"></param>
1870
        /// <param name="endSymbol"></param>
1871
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1872
        {
1873
            string symbolPath = string.Empty;
1874
            #region get symbol path
1875
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1876
            foreach (LMRepresentation rep in modelItem.Representations)
1877
            {
1878
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1879
                {
1880
                    symbolPath = rep.get_FileName();
1881
                    break;
1882
                }
1883
            }
1884
            #endregion
1885
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1886
            LMConnector newConnector = null;
1887
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
1888
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1889
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1890
            int verticesCount = lineStringGeometry.VertexCount;
1891
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1892

    
1893
            List<double[]> vertices = new List<double[]>();
1894
            for (int i = 1; i <= verticesCount; i++)
1895
            {
1896
                double x = 0;
1897
                double y = 0;
1898
                lineStringGeometry.GetVertex(i, ref x, ref y);
1899
                vertices.Add(new double[] { x, y });
1900
            }
1901

    
1902
            for (int i = 0; i < vertices.Count; i++)
1903
            {
1904
                double[] points = vertices[i];
1905
                // 시작 심볼이 있고 첫번째 좌표일 때
1906
                if (startSymbol != null && i == 0)
1907
                {
1908
                    if (bStart)
1909
                    {
1910
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1911
                        if (slopeType == SlopeType.HORIZONTAL)
1912
                            placeRunInputs.AddPoint(points[0], -0.1);
1913
                        else if (slopeType == SlopeType.VERTICAL)
1914
                            placeRunInputs.AddPoint(-0.1, points[1]);
1915
                        else
1916
                            placeRunInputs.AddPoint(points[0], -0.1);
1917

    
1918
                        placeRunInputs.AddPoint(points[0], points[1]);
1919
                    }
1920
                    else
1921
                    {
1922
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1]);
1923
                    }
1924
                }
1925
                // 마지막 심볼이 있고 마지막 좌표일 때
1926
                else if (endSymbol != null && i == vertices.Count - 1)
1927
                {
1928
                    if (bEnd)
1929
                    {
1930
                        placeRunInputs.AddPoint(points[0], points[1]);
1931

    
1932
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1933
                        if (slopeType == SlopeType.HORIZONTAL)
1934
                            placeRunInputs.AddPoint(points[0], -0.1);
1935
                        else if (slopeType == SlopeType.VERTICAL)
1936
                            placeRunInputs.AddPoint(-0.1, points[1]);
1937
                        else
1938
                            placeRunInputs.AddPoint(points[0], -0.1);
1939
                    }
1940
                    else
1941
                    {
1942
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1]);
1943
                    }
1944
                }
1945
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1946
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1947
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1948
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1949
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1950
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1951
                else
1952
                    placeRunInputs.AddPoint(points[0], points[1]);
1953
            }
1954

    
1955
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1956
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1957

    
1958
            ReleaseCOMObjects(placeRunInputs);
1959
            ReleaseCOMObjects(_LMAItem);
1960
            ReleaseCOMObjects(modelItem);
1961

    
1962
            if (newConnector != null)
1963
            {
1964
                if (startSymbol != null && bStart)
1965
                {
1966
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1967
                    placeRunInputs = new PlaceRunInputs();
1968
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1969
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][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
                if (endSymbol != null && bEnd)
1982
                {
1983
                    if (startSymbol != null)
1984
                    {
1985
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1986
                        newConnector = dicVertices.First().Key;
1987
                    }
1988

    
1989
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1990
                    placeRunInputs = new PlaceRunInputs();
1991
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1992
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1993
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1994
                    if (_LMConnector != null)
1995
                    {
1996
                        RemoveConnectorForReModelingLine(newConnector);
1997
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
1998
                        ReleaseCOMObjects(_LMConnector);
1999
                    }
2000
                    ReleaseCOMObjects(placeRunInputs);
2001
                    ReleaseCOMObjects(_LMAItem);
2002
                }
2003

    
2004
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2005
                ReleaseCOMObjects(newConnector);
2006
            }
2007

    
2008
            ReleaseCOMObjects(modelItem);
2009
        }
2010

    
2011
        /// <summary>
2012
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
2013
        /// </summary>
2014
        /// <param name="connector"></param>
2015
        private void RemoveConnectorForReModelingLine(LMConnector connector)
2016
        {
2017
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
2018
            foreach (var item in dicVertices)
2019
            {
2020
                if (item.Value.Count == 2)
2021
                {
2022
                    bool result = false;
2023
                    foreach (var point in item.Value)
2024
                    {
2025
                        if (point[0] < 0 || point[1] < 0)
2026
                        {
2027
                            result = true;
2028
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2029
                            break;
2030
                        }
2031
                    }
2032

    
2033
                    if (result)
2034
                        break;
2035
                }
2036
            }
2037
            foreach (var item in dicVertices)
2038
                ReleaseCOMObjects(item.Key);
2039
        }
2040

    
2041
        /// <summary>
2042
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2043
        /// </summary>
2044
        /// <param name="symbol"></param>
2045
        /// <param name="line"></param>
2046
        /// <returns></returns>
2047
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2048
        {
2049
            LMSymbol _LMSymbol = null;
2050
            foreach (var connector in symbol.CONNECTORS)
2051
            {
2052
                if (connector.CONNECTEDITEM == line.UID)
2053
                {
2054
                    if (connector.Index == 0)
2055
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2056
                    else
2057
                    {
2058
                        ChildSymbol child = null;
2059
                        foreach (var childSymbol in symbol.ChildSymbols)
2060
                        {
2061
                            if (childSymbol.Connectors.Contains(connector))
2062
                                child = childSymbol;
2063
                            else
2064
                                child = GetChildSymbolByConnector(childSymbol, connector);
2065

    
2066
                            if (child != null)
2067
                                break;
2068
                        }
2069

    
2070
                        if (child != null)
2071
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2072
                    }
2073

    
2074
                    break;
2075
                }
2076
            }
2077

    
2078
            return _LMSymbol;
2079
        }
2080

    
2081
        /// <summary>
2082
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2083
        /// </summary>
2084
        /// <param name="item"></param>
2085
        /// <param name="connector"></param>
2086
        /// <returns></returns>
2087
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2088
        {
2089
            foreach (var childSymbol in item.ChildSymbols)
2090
            {
2091
                if (childSymbol.Connectors.Contains(connector))
2092
                    return childSymbol;
2093
                else
2094
                    return GetChildSymbolByConnector(childSymbol, connector);
2095
            }
2096

    
2097
            return null;
2098
        }
2099

    
2100
        /// <summary>
2101
        /// EndBreak 모델링 메서드
2102
        /// </summary>
2103
        /// <param name="endBreak"></param>
2104
        private void EndBreakModeling(EndBreak endBreak)
2105
        {
2106
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2107
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2108
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2109

    
2110
            if (targetLMConnector != null)
2111
            {
2112
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2113
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2114
                if (_LmLabelPersist != null)
2115
                {
2116
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2117
                    if (_LmLabelPersist.ModelItemObject != null)
2118
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2119
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2120
                    ReleaseCOMObjects(_LmLabelPersist);
2121
                }
2122
                ReleaseCOMObjects(targetLMConnector);
2123
            }
2124
        }
2125

    
2126
        private LMConnector ReModelingLMConnector(LMConnector connector)
2127
        {
2128
            string symbolPath = string.Empty;
2129
            #region get symbol path
2130
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2131
            foreach (LMRepresentation rep in modelItem.Representations)
2132
            {
2133
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2134
                {
2135
                    symbolPath = rep.get_FileName();
2136
                    break;
2137
                }
2138
            }
2139
            #endregion
2140

    
2141
            LMConnector newConnector = null;
2142
            dynamic OID = connector.get_GraphicOID().ToString();
2143
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2144
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2145
            int verticesCount = lineStringGeometry.VertexCount;
2146
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2147
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2148

    
2149
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2150
            {
2151
                double[] vertices = null;
2152
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2153
                double x = 0;
2154
                double y = 0;
2155
                lineStringGeometry.GetVertex(1, ref x, ref y);
2156

    
2157
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2158
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2159

    
2160
                string flowDirection = string.Empty;
2161
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2162
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2163
                    flowDirection = flowAttribute.get_Value().ToString();
2164

    
2165
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2166
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2167
                ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID);
2168
                if (!string.IsNullOrEmpty(flowDirection))
2169
                    newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection);
2170
            }
2171
            else
2172
            {
2173
                List<double[]> vertices = new List<double[]>();
2174
                for (int i = 1; i <= verticesCount; i++)
2175
                {
2176
                    double x = 0;
2177
                    double y = 0;
2178
                    lineStringGeometry.GetVertex(i, ref x, ref y);
2179
                    vertices.Add(new double[] { x, y });
2180
                }
2181

    
2182
                for (int i = 0; i < vertices.Count; i++)
2183
                {
2184
                    double[] points = vertices[i];
2185
                    if (i == 0)
2186
                    {
2187
                        if (connector.ConnectItem1SymbolObject != null)
2188
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
2189
                        else
2190
                            placeRunInputs.AddPoint(points[0], points[1]);
2191
                    }
2192
                    else if (i == vertices.Count - 1)
2193
                    {
2194
                        if (connector.ConnectItem2SymbolObject != null)
2195
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
2196
                        else
2197
                            placeRunInputs.AddPoint(points[0], points[1]);
2198
                    }
2199
                    else
2200
                        placeRunInputs.AddPoint(points[0], points[1]);
2201
                }
2202

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

    
2205
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2206
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2207

    
2208
                foreach (var line in lines)
2209
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
2210
            }
2211

    
2212

    
2213
            return newConnector;
2214
        }
2215

    
2216
        /// <summary>
2217
        /// SpecBreak Modeling 메서드
2218
        /// </summary>
2219
        /// <param name="specBreak"></param>
2220
        private void SpecBreakModeling(SpecBreak specBreak)
2221
        {
2222
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2223
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2224

    
2225
            if (upStreamObj != null &&
2226
                downStreamObj != null)
2227
            {
2228
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2229

    
2230
                if (targetLMConnector != null)
2231
                {
2232
                    foreach (var attribute in specBreak.ATTRIBUTES)
2233
                    {
2234
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2235
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2236
                        {
2237
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2238
                            Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2239
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2240

    
2241
                            if (_LmLabelPersist != null)
2242
                            {
2243
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2244
                                if (_LmLabelPersist.ModelItemObject != null)
2245
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2246
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2247
                                ReleaseCOMObjects(_LmLabelPersist);
2248
                            }
2249
                        }
2250
                    }
2251
                    ReleaseCOMObjects(targetLMConnector);
2252
                }
2253
            }
2254
        }
2255

    
2256
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2257
        {
2258
            LMConnector targetConnector = null;
2259
            Symbol targetSymbol = targetObj as Symbol;
2260
            Symbol connectedSymbol = connectedObj as Symbol;
2261
            Line targetLine = targetObj as Line;
2262
            Line connectedLine = connectedObj as Line;
2263
            if (targetSymbol != null && connectedSymbol != null)
2264
            {
2265
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2266
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2267

    
2268
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2269
                {
2270
                    if (connector.get_ItemStatus() != "Active")
2271
                        continue;
2272

    
2273
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2274
                    {
2275
                        targetConnector = connector;
2276
                        break;
2277
                    }
2278
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2279
                    {
2280
                        targetConnector = connector;
2281
                        break;
2282
                    }
2283
                }
2284

    
2285
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2286
                {
2287
                    if (connector.get_ItemStatus() != "Active")
2288
                        continue;
2289

    
2290
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2291
                    {
2292
                        targetConnector = connector;
2293
                        break;
2294
                    }
2295
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2296
                    {
2297
                        targetConnector = connector;
2298
                        break;
2299
                    }
2300
                }
2301

    
2302
                ReleaseCOMObjects(targetLMSymbol);
2303
                ReleaseCOMObjects(connectedLMSymbol);
2304
            }
2305
            else if (targetLine != null && connectedLine != null)
2306
            {
2307
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2308
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2309

    
2310
                if (targetModelItem != null && connectedModelItem != null)
2311
                {
2312
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2313
                    {
2314
                        if (targetConnector != null)
2315
                            break;
2316

    
2317
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2318
                        {
2319
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2320

    
2321
                            if (IsConnected(_LMConnector, connectedModelItem))
2322
                                targetConnector = _LMConnector;
2323
                            else
2324
                                ReleaseCOMObjects(_LMConnector);
2325
                        }
2326
                    }
2327

    
2328
                    ReleaseCOMObjects(targetModelItem);
2329
                }
2330
            }
2331
            else
2332
            {
2333
                LMSymbol connectedLMSymbol = null;
2334
                if (connectedSymbol != null)
2335
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2336
                else if (targetSymbol != null)
2337
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2338
                else
2339
                {
2340

    
2341
                }
2342
                LMModelItem targetModelItem = null;
2343
                if (targetLine != null)
2344
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2345
                else if (connectedLine != null)
2346
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2347
                else
2348
                {
2349

    
2350
                }
2351
                if (connectedLMSymbol != null && targetModelItem != null)
2352
                {
2353
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2354
                    {
2355
                        if (connector.get_ItemStatus() != "Active")
2356
                            continue;
2357

    
2358
                        if (IsConnected(connector, targetModelItem))
2359
                        {
2360
                            targetConnector = connector;
2361
                            break;
2362
                        }
2363
                    }
2364

    
2365
                    if (targetConnector == null)
2366
                    {
2367
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2368
                        {
2369
                            if (connector.get_ItemStatus() != "Active")
2370
                                continue;
2371

    
2372
                            if (IsConnected(connector, targetModelItem))
2373
                            {
2374
                                targetConnector = connector;
2375
                                break;
2376
                            }
2377
                        }
2378
                    }
2379
                }
2380

    
2381
            }
2382

    
2383
            return targetConnector;
2384
        }
2385

    
2386
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2387
        {
2388
            bool result = false;
2389

    
2390
            foreach (LMRepresentation rep in modelItem.Representations)
2391
            {
2392
                if (result)
2393
                    break;
2394

    
2395
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2396
                {
2397
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2398

    
2399
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2400
                        connector.ConnectItem1SymbolObject != null &&
2401
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2402
                    {
2403
                        result = true;
2404
                        ReleaseCOMObjects(_LMConnector);
2405
                        break;
2406
                    }
2407
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2408
                        connector.ConnectItem2SymbolObject != null &&
2409
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2410
                    {
2411
                        result = true;
2412
                        ReleaseCOMObjects(_LMConnector);
2413
                        break;
2414
                    }
2415
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2416
                        connector.ConnectItem1SymbolObject != null &&
2417
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2418
                    {
2419
                        result = true;
2420
                        ReleaseCOMObjects(_LMConnector);
2421
                        break;
2422
                    }
2423
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2424
                        connector.ConnectItem2SymbolObject != null &&
2425
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2426
                    {
2427
                        result = true;
2428
                        ReleaseCOMObjects(_LMConnector);
2429
                        break;
2430
                    }
2431

    
2432
                    ReleaseCOMObjects(_LMConnector);
2433
                }
2434
            }
2435

    
2436

    
2437
            return result;
2438
        }
2439

    
2440
        /// <summary>
2441
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2442
        /// </summary>
2443
        /// <param name="modelItemID1"></param>
2444
        /// <param name="modelItemID2"></param>
2445
        private void JoinPipeRun(string modelItemID1, string modelItemID2)
2446
        {
2447
            LMModelItem modelItem1 = dataSource.GetModelItem(modelItemID2);
2448
            _LMAItem item1 = modelItem1.AsLMAItem();
2449
            LMModelItem modelItem2 = dataSource.GetModelItem(modelItemID1);
2450
            _LMAItem item2 = modelItem2.AsLMAItem();
2451

    
2452
            // item2가 item1으로 조인
2453
            _placement.PIDJoinRuns(ref item1, ref item2);
2454
            item1.Commit();
2455
            item2.Commit();
2456

    
2457
            string beforeID = string.Empty;
2458
            string afterID = string.Empty;
2459

    
2460
            if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
2461
            {
2462
                beforeID = modelItem2.Id;
2463
                afterID = modelItem1.Id;
2464
            }
2465
            else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
2466
            {
2467
                beforeID = modelItem1.Id;
2468
                afterID = modelItem2.Id;
2469
            }
2470
            else
2471
            {
2472
                throw new Exception("확인 필요한 케이스");
2473
            }
2474

    
2475
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
2476
            foreach (var line in lines)
2477
                line.SPPID.ModelItemId = afterID;
2478

    
2479
            ReleaseCOMObjects(modelItem1);
2480
            ReleaseCOMObjects(item1);
2481
            ReleaseCOMObjects(modelItem2);
2482
            ReleaseCOMObjects(item2);
2483
        }
2484

    
2485
        /// <summary>
2486
        /// PipeRun을 자동으로 Join하는 메서드
2487
        /// </summary>
2488
        /// <param name="modelItemId"></param>
2489
        private void AutoJoinPipeRun(string modelItemId)
2490
        {
2491
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
2492
            _LMAItem item = modelItem.AsLMAItem();
2493
            if (modelItem.get_ItemStatus() == "Active")
2494
            {
2495
                string modelitemID = item.Id;
2496
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
2497
                string afterModelItemID = item.Id;
2498

    
2499
                if (modelitemID != afterModelItemID)
2500
                {
2501
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
2502
                    foreach (var line in lines)
2503
                        line.SPPID.ModelItemId = afterModelItemID;
2504
                }
2505
                item.Commit();
2506
            }
2507

    
2508
            ReleaseCOMObjects(modelItem);
2509
            ReleaseCOMObjects(item);
2510
        }
2511

    
2512
        /// <summary>
2513
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
2514
        /// </summary>
2515
        /// <param name="run"></param>
2516
        private void JoinRunLine(LineRun run)
2517
        {
2518
            string modelItemId = string.Empty;
2519
            foreach (var item in run.RUNITEMS)
2520
            {
2521
                if (item.GetType() == typeof(Line))
2522
                {
2523
                    Line line = item as Line;
2524
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
2525
                    modelItemId = line.SPPID.ModelItemId;
2526
                }
2527
            }
2528
        }
2529

    
2530
        /// <summary>
2531
        /// PipeRun의 좌표를 가져오는 메서드
2532
        /// </summary>
2533
        /// <param name="modelId"></param>
2534
        /// <returns></returns>
2535
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2536
        {
2537
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2538
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2539

    
2540
            if (modelItem != null)
2541
            {
2542
                foreach (LMRepresentation rep in modelItem.Representations)
2543
                {
2544
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2545
                    {
2546
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2547
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2548
                        dynamic OID = rep.get_GraphicOID().ToString();
2549
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2550
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2551
                        int verticesCount = lineStringGeometry.VertexCount;
2552
                        double[] vertices = null;
2553
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2554
                        for (int i = 0; i < verticesCount; i++)
2555
                        {
2556
                            double x = 0;
2557
                            double y = 0;
2558
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2559
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
2560
                        }
2561
                    }
2562
                }
2563

    
2564
                ReleaseCOMObjects(modelItem);
2565
            }
2566

    
2567
            return connectorVertices;
2568
        }
2569

    
2570
        private List<double[]> GetConnectorVertices(LMConnector connector)
2571
        {
2572
            List<double[]> vertices = new List<double[]>();
2573
            dynamic OID = connector.get_GraphicOID().ToString();
2574
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2575
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2576
            int verticesCount = lineStringGeometry.VertexCount;
2577
            double[] value = null;
2578
            lineStringGeometry.GetVertices(ref verticesCount, ref value);
2579
            for (int i = 0; i < verticesCount; i++)
2580
            {
2581
                double x = 0;
2582
                double y = 0;
2583
                lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2584
                vertices.Add(new double[] { x, y });
2585
            }
2586
            return vertices;
2587
        }
2588

    
2589
        /// <summary>
2590
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2591
        /// </summary>
2592
        /// <param name="connectorVertices"></param>
2593
        /// <param name="connX"></param>
2594
        /// <param name="connY"></param>
2595
        /// <returns></returns>
2596
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2597
        {
2598
            double length = double.MaxValue;
2599
            LMConnector targetConnector = null;
2600
            foreach (var item in connectorVertices)
2601
            {
2602
                List<double[]> points = item.Value;
2603
                for (int i = 0; i < points.Count - 1; i++)
2604
                {
2605
                    double[] point1 = points[i];
2606
                    double[] point2 = points[i + 1];
2607
                    double x1 = Math.Min(point1[0], point2[0]);
2608
                    double y1 = Math.Min(point1[1], point2[1]);
2609
                    double x2 = Math.Max(point1[0], point2[0]);
2610
                    double y2 = Math.Max(point1[1], point2[1]);
2611

    
2612
                    if ((x1 <= connX && x2 >= connX) ||
2613
                        (y1 <= connY && y2 >= connY))
2614
                    {
2615
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2616
                        if (length >= distance)
2617
                        {
2618
                            targetConnector = item.Key;
2619
                            length = distance;
2620
                        }
2621

    
2622
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2623
                        if (length >= distance)
2624
                        {
2625
                            targetConnector = item.Key;
2626
                            length = distance;
2627
                        }
2628
                    }
2629
                }
2630
            }
2631

    
2632
            // 못찾았을때.
2633
            length = double.MaxValue;
2634
            if (targetConnector == null)
2635
            {
2636
                foreach (var item in connectorVertices)
2637
                {
2638
                    List<double[]> points = item.Value;
2639

    
2640
                    foreach (double[] point in points)
2641
                    {
2642
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2643
                        if (length >= distance)
2644
                        {
2645
                            targetConnector = item.Key;
2646
                            length = distance;
2647
                        }
2648
                    }
2649
                }
2650
            }
2651

    
2652
            return targetConnector;
2653
        }
2654

    
2655
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
2656
        {
2657
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
2658

    
2659
            double length = double.MaxValue;
2660
            LMConnector targetConnector = null;
2661
            double[] resultPoint = null;
2662
            List<double[]> targetVertices = null;
2663

    
2664
            // Vertices 포인트에 제일 가까운곳
2665
            foreach (var item in vertices)
2666
            {
2667
                List<double[]> points = item.Value;
2668
                for (int i = 0; i < points.Count; i++)
2669
                {
2670
                    double[] point = points[i];
2671
                    double tempX = point[0];
2672
                    double tempY = point[1];
2673

    
2674
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
2675
                    if (length >= distance)
2676
                    {
2677
                        targetConnector = item.Key;
2678
                        length = distance;
2679
                        resultPoint = point;
2680
                        targetVertices = item.Value;
2681
                    }
2682
                }
2683
            }
2684

    
2685
            // Vertices Cross에 제일 가까운곳
2686
            foreach (var item in vertices)
2687
            {
2688
                List<double[]> points = item.Value;
2689
                for (int i = 0; i < points.Count - 1; i++)
2690
                {
2691
                    double[] point1 = points[i];
2692
                    double[] point2 = points[i + 1];
2693

    
2694
                    double maxLineX = Math.Max(point1[0], point2[0]);
2695
                    double minLineX = Math.Min(point1[0], point2[0]);
2696
                    double maxLineY = Math.Max(point1[1], point2[1]);
2697
                    double minLineY = Math.Min(point1[1], point2[1]);
2698

    
2699
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2700

    
2701
                    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]);
2702
                    if (crossingPoint != null)
2703
                    {
2704
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
2705
                        if (length >= distance)
2706
                        {
2707
                            if (slope == SlopeType.Slope &&
2708
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2709
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2710
                            {
2711
                                targetConnector = item.Key;
2712
                                length = distance;
2713
                                resultPoint = crossingPoint;
2714
                                targetVertices = item.Value;
2715
                            }
2716
                            else if (slope == SlopeType.HORIZONTAL &&
2717
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2718
                            {
2719
                                targetConnector = item.Key;
2720
                                length = distance;
2721
                                resultPoint = crossingPoint;
2722
                                targetVertices = item.Value;
2723
                            }
2724
                            else if (slope == SlopeType.VERTICAL &&
2725
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2726
                            {
2727
                                targetConnector = item.Key;
2728
                                length = distance;
2729
                                resultPoint = crossingPoint;
2730
                                targetVertices = item.Value;
2731
                            }
2732
                        }
2733
                    }
2734
                }
2735
            }
2736

    
2737
            foreach (var item in vertices)
2738
                if (item.Key != null && item.Key != targetConnector)
2739
                    ReleaseCOMObjects(item.Key);
2740

    
2741
            if (SPPIDUtil.IsBranchLine(line, targetLine))
2742
            {
2743
                double tempResultX = resultPoint[0];
2744
                double tempResultY = resultPoint[1];
2745
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
2746

    
2747
                GridSetting gridSetting = GridSetting.GetInstance();
2748

    
2749
                for (int i = 0; i < targetVertices.Count; i++)
2750
                {
2751
                    double[] point = targetVertices[i];
2752
                    double tempX = targetVertices[i][0];
2753
                    double tempY = targetVertices[i][1];
2754
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
2755
                    if (tempX == tempResultX && tempY == tempResultY)
2756
                    {
2757
                        if (i == 0)
2758
                        {
2759
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
2760
                            bool containZeroLength = false;
2761
                            if (connSymbol != null)
2762
                            {
2763
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2764
                                {
2765
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2766
                                        containZeroLength = true;
2767
                                }
2768
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2769
                                {
2770
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2771
                                        containZeroLength = true;
2772
                                }
2773
                            }
2774

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

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

    
2810
                                if (bCalcY)
2811
                                {
2812
                                    double nextY = targetVertices[i + 1][1];
2813
                                    double newY = 0;
2814
                                    if (nextY > tempY)
2815
                                    {
2816
                                        newY = tempY + gridSetting.Length;
2817
                                        if (newY > nextY)
2818
                                            newY = (point[1] + nextY) / 2;
2819
                                    }
2820
                                    else
2821
                                    {
2822
                                        newY = tempY - gridSetting.Length;
2823
                                        if (newY < nextY)
2824
                                            newY = (point[1] + nextY) / 2;
2825
                                    }
2826
                                    resultPoint = new double[] { resultPoint[0], newY };
2827
                                }
2828
                            }
2829
                        }
2830
                        else if (i == targetVertices.Count - 1)
2831
                        {
2832
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
2833
                            bool containZeroLength = false;
2834
                            if (connSymbol != null)
2835
                            {
2836
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2837
                                {
2838
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2839
                                        containZeroLength = true;
2840
                                }
2841
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2842
                                {
2843
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2844
                                        containZeroLength = true;
2845
                                }
2846
                            }
2847

    
2848
                            if (connSymbol == null ||
2849
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2850
                                containZeroLength)
2851
                            {
2852
                                bool bCalcX = false;
2853
                                bool bCalcY = false;
2854
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2855
                                    bCalcX = true;
2856
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2857
                                    bCalcY = true;
2858
                                else
2859
                                {
2860
                                    bCalcX = true;
2861
                                    bCalcY = true;
2862
                                }
2863

    
2864
                                if (bCalcX)
2865
                                {
2866
                                    double nextX = targetVertices[i - 1][0];
2867
                                    double newX = 0;
2868
                                    if (nextX > tempX)
2869
                                    {
2870
                                        newX = tempX + gridSetting.Length;
2871
                                        if (newX > nextX)
2872
                                            newX = (point[0] + nextX) / 2;
2873
                                    }
2874
                                    else
2875
                                    {
2876
                                        newX = tempX - gridSetting.Length;
2877
                                        if (newX < nextX)
2878
                                            newX = (point[0] + nextX) / 2;
2879
                                    }
2880
                                    resultPoint = new double[] { newX, resultPoint[1] };
2881
                                }
2882

    
2883
                                if (bCalcY)
2884
                                {
2885
                                    double nextY = targetVertices[i - 1][1];
2886
                                    double newY = 0;
2887
                                    if (nextY > tempY)
2888
                                    {
2889
                                        newY = tempY + gridSetting.Length;
2890
                                        if (newY > nextY)
2891
                                            newY = (point[1] + nextY) / 2;
2892
                                    }
2893
                                    else
2894
                                    {
2895
                                        newY = tempY - gridSetting.Length;
2896
                                        if (newY < nextY)
2897
                                            newY = (point[1] + nextY) / 2;
2898
                                    }
2899
                                    resultPoint = new double[] { resultPoint[0], newY };
2900
                                }
2901
                            }
2902
                        }
2903
                        break;
2904
                    }
2905
                }
2906
            }
2907

    
2908
            x = resultPoint[0];
2909
            y = resultPoint[1];
2910

    
2911
            return targetConnector;
2912
        }
2913

    
2914
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
2915
        {
2916
            LMConnector result = null;
2917
            List<LMConnector> connectors = new List<LMConnector>();
2918
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
2919

    
2920
            if (modelItem != null)
2921
            {
2922
                foreach (LMRepresentation rep in modelItem.Representations)
2923
                {
2924
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2925
                        connectors.Add(dataSource.GetConnector(rep.Id));
2926
                }
2927

    
2928
                ReleaseCOMObjects(modelItem);
2929
            }
2930

    
2931
            if (connectors.Count == 1)
2932
                result = connectors[0];
2933
            else
2934
                foreach (var item in connectors)
2935
                    ReleaseCOMObjects(item);
2936

    
2937
            return result;
2938
        }
2939

    
2940
        /// <summary>
2941
        /// Line Number Symbol을 실제로 Modeling하는 메서드
2942
        /// </summary>
2943
        /// <param name="lineNumber"></param>
2944
        private void LineNumberModeling(Line line)
2945
        {
2946
            LineNumber lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == line.UID);
2947
            if (lineNumber != null)
2948
            {
2949
                LMConnector connectedLMConnector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
2950
                if (connectedLMConnector != null)
2951
                {
2952
                    double x = 0;
2953
                    double y = 0;
2954
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
2955

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

    
2959
                    if (_LmLabelPresist != null)
2960
                    {
2961
                        _LmLabelPresist.Commit();
2962
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
2963
                        ReleaseCOMObjects(_LmLabelPresist);
2964
                    }
2965
                }
2966
            }
2967
        }
2968
        /// <summary>
2969
        /// Flow Mark Modeling
2970
        /// </summary>
2971
        /// <param name="line"></param>
2972
        private void FlowMarkModeling(Line line)
2973
        {
2974
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
2975
            {
2976
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
2977
                if (connector != null)
2978
                {
2979
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
2980
                    List<double[]> vertices = GetConnectorVertices(connector);
2981
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
2982
                    double[] point = vertices[vertices.Count - 1];
2983
                    Array array = new double[] { 0, point[0], point[1] };
2984
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
2985
                    if (_LMLabelPersist != null)
2986
                        ReleaseCOMObjects(_LMLabelPersist);
2987
                }
2988
            }
2989
        }
2990

    
2991
        /// <summary>
2992
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
2993
        /// </summary>
2994
        /// <param name="lineNumber"></param>
2995
        private void InputLineNumberAttribute(LineNumber lineNumber)
2996
        {
2997
            foreach (LineRun run in lineNumber.RUNS)
2998
            {
2999
                foreach (var item in run.RUNITEMS)
3000
                {
3001
                    //if (item.GetType() == typeof(Symbol))
3002
                    //{
3003
                    //    Symbol symbol = item as Symbol;
3004
                    //    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3005
                    //    if (_LMSymbol != null)
3006
                    //    {
3007
                    //        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3008

    
3009
                    //        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3010
                    //        {
3011
                    //            foreach (var attribute in lineNumber.ATTRIBUTES)
3012
                    //            {
3013
                    //                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3014
                    //                if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3015
                    //                {
3016
                    //                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3017
                    //                    if (_LMAAttribute != null)
3018
                    //                    {
3019
                    //                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3020
                    //                            _LMAAttribute.set_Value(attribute.VALUE);
3021
                    //                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
3022
                    //                            _LMAAttribute.set_Value(attribute.VALUE);
3023
                    //                    }
3024
                    //                }
3025
                    //            }
3026
                    //            _LMModelItem.Commit();
3027
                    //        }
3028
                    //        if (_LMModelItem != null)
3029
                    //            ReleaseCOMObjects(_LMModelItem);
3030
                    //    }
3031
                    //    if (_LMSymbol != null)
3032
                    //        ReleaseCOMObjects(_LMSymbol);
3033
                    //}
3034
                    //else
3035
                    if (item.GetType() == typeof(Line))
3036
                    {
3037
                        Line line = item as Line;
3038
                        if (line != null)
3039
                        {
3040
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3041
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3042
                            {
3043
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3044
                                {
3045
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3046
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3047
                                    {
3048
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3049
                                        if (_LMAAttribute != null)
3050
                                        {
3051
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3052
                                                _LMAAttribute.set_Value(attribute.VALUE);
3053
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3054
                                                _LMAAttribute.set_Value(attribute.VALUE);
3055

    
3056
                                        }
3057
                                    }
3058
                                }
3059
                                _LMModelItem.Commit();
3060
                            }
3061
                            if (_LMModelItem != null)
3062
                                ReleaseCOMObjects(_LMModelItem);
3063

    
3064
                            break;
3065
                        }
3066
                    }
3067
                }
3068
            }
3069
        }
3070

    
3071
        /// <summary>
3072
        /// Symbol Attribute 입력 메서드
3073
        /// </summary>
3074
        /// <param name="item"></param>
3075
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3076
        {
3077

    
3078
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3079
            string sRep = null;
3080
            if (targetItem.GetType() == typeof(Symbol))
3081
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3082
            else if (targetItem.GetType() == typeof(Equipment))
3083
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3084

    
3085
            if (!string.IsNullOrEmpty(sRep))
3086
            {
3087
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3088
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3089
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3090

    
3091
                foreach (var item in targetAttributes)
3092
                {
3093
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3094
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3095
                    {
3096
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3097
                        if (_Attribute != null)
3098
                            _Attribute.set_Value(item.VALUE);
3099
                    }
3100
                }
3101
                _LMModelItem.Commit();
3102

    
3103
                ReleaseCOMObjects(_Attributes);
3104
                ReleaseCOMObjects(_LMModelItem);
3105
                ReleaseCOMObjects(_LMSymbol);
3106
            }
3107
        }
3108

    
3109
        /// <summary>
3110
        /// Input SpecBreak Attribute
3111
        /// </summary>
3112
        /// <param name="specBreak"></param>
3113
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3114
        {
3115
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3116
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3117

    
3118
            if (upStreamObj != null &&
3119
                downStreamObj != null)
3120
            {
3121
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3122

    
3123
                if (targetLMConnector != null)
3124
                {
3125
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
3126
                    {
3127
                        string symbolPath = _LMLabelPersist.get_FileName();
3128
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
3129
                        if (mapping != null)
3130
                        {
3131
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
3132
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3133
                            {
3134
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
3135
                                if (values.Length == 2)
3136
                                {
3137
                                    string upStreamValue = values[0];
3138
                                    string downStreamValue = values[1];
3139

    
3140
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3141
                                }
3142
                            }
3143
                        }
3144
                    }
3145

    
3146
                    ReleaseCOMObjects(targetLMConnector);
3147
                }
3148
            }
3149

    
3150

    
3151
            #region 내부에서만 쓰는 메서드
3152
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
3153
            {
3154
                Symbol upStreamSymbol = _upStreamObj as Symbol;
3155
                Line upStreamLine = _upStreamObj as Line;
3156
                Symbol downStreamSymbol = _downStreamObj as Symbol;
3157
                Line downStreamLine = _downStreamObj as Line;
3158
                // 둘다 Line일 경우
3159
                if (upStreamLine != null && downStreamLine != null)
3160
                {
3161
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3162
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3163
                }
3164
                // 둘다 Symbol일 경우
3165
                else if (upStreamSymbol != null && downStreamSymbol != null)
3166
                {
3167
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
3168
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3169
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3170

    
3171
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3172
                    {
3173
                        if (connector.get_ItemStatus() != "Active")
3174
                            continue;
3175

    
3176
                        if (connector.Id != zeroLenthConnector.Id)
3177
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3178
                    }
3179

    
3180
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3181
                    {
3182
                        if (connector.get_ItemStatus() != "Active")
3183
                            continue;
3184

    
3185
                        if (connector.Id != zeroLenthConnector.Id)
3186
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3187
                    }
3188

    
3189
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3190
                    {
3191
                        if (connector.get_ItemStatus() != "Active")
3192
                            continue;
3193

    
3194
                        if (connector.Id != zeroLenthConnector.Id)
3195
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3196
                    }
3197

    
3198
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3199
                    {
3200
                        if (connector.get_ItemStatus() != "Active")
3201
                            continue;
3202

    
3203
                        if (connector.Id != zeroLenthConnector.Id)
3204
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3205
                    }
3206

    
3207
                    ReleaseCOMObjects(zeroLenthConnector);
3208
                    ReleaseCOMObjects(upStreamLMSymbol);
3209
                    ReleaseCOMObjects(downStreamLMSymbol);
3210
                }
3211
                else if (upStreamSymbol != null && downStreamLine != null)
3212
                {
3213
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3214
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3215
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3216

    
3217
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3218
                    {
3219
                        if (connector.get_ItemStatus() != "Active")
3220
                            continue;
3221

    
3222
                        if (connector.Id != zeroLenthConnector.Id)
3223
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3224
                    }
3225

    
3226
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3227
                    {
3228
                        if (connector.get_ItemStatus() != "Active")
3229
                            continue;
3230

    
3231
                        if (connector.Id != zeroLenthConnector.Id)
3232
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3233
                    }
3234

    
3235
                    ReleaseCOMObjects(zeroLenthConnector);
3236
                    ReleaseCOMObjects(upStreamLMSymbol);
3237
                }
3238
                else if (upStreamLine != null && downStreamSymbol != null)
3239
                {
3240
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3241
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3242
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3243

    
3244
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3245
                    {
3246
                        if (connector.get_ItemStatus() != "Active")
3247
                            continue;
3248

    
3249
                        if (connector.Id != zeroLenthConnector.Id)
3250
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3251
                    }
3252

    
3253
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3254
                    {
3255
                        if (connector.get_ItemStatus() != "Active")
3256
                            continue;
3257

    
3258
                        if (connector.Id != zeroLenthConnector.Id)
3259
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3260
                    }
3261

    
3262
                    ReleaseCOMObjects(zeroLenthConnector);
3263
                    ReleaseCOMObjects(downStreamLMSymbol);
3264
                }
3265
            }
3266

    
3267
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3268
            {
3269
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3270
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3271
                {
3272
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3273
                    if (_LMAAttribute != null)
3274
                    {
3275
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3276
                            _LMAAttribute.set_Value(value);
3277
                        else if (_LMAAttribute.get_Value() != value)
3278
                            _LMAAttribute.set_Value(value);
3279
                    }
3280

    
3281
                    _LMModelItem.Commit();
3282
                }
3283
                if (_LMModelItem != null)
3284
                    ReleaseCOMObjects(_LMModelItem);
3285
            }
3286

    
3287
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3288
            {
3289
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3290
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3291
                {
3292
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3293
                    if (_LMAAttribute != null)
3294
                    {
3295
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3296
                            _LMAAttribute.set_Value(value);
3297
                        else if (_LMAAttribute.get_Value() != value)
3298
                            _LMAAttribute.set_Value(value);
3299
                    }
3300

    
3301
                    _LMModelItem.Commit();
3302
                }
3303
                if (_LMModelItem != null)
3304
                    ReleaseCOMObjects(_LMModelItem);
3305
            }
3306
            #endregion
3307
        }
3308

    
3309
        /// <summary>
3310
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3311
        /// </summary>
3312
        /// <param name="text"></param>
3313
        private void TextModeling(Text text)
3314
        {
3315
            LMSymbol _LMSymbol = null;
3316
            LMConnector connectedLMConnector = null;
3317
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
3318
            if (text.ASSOCIATION)
3319
            {
3320
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
3321
                if (owner.GetType() == typeof(Symbol))
3322
                {
3323
                    Symbol symbol = owner as Symbol;
3324
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3325
                    if (_LMSymbol != null)
3326
                    {
3327
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3328
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3329
                        {
3330
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3331

    
3332
                            if (mapping != null)
3333
                            {
3334
                                double x = 0;
3335
                                double y = 0;
3336

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

    
3340
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3341
                                if (_LMLabelPersist != null)
3342
                                {
3343
                                    _LMLabelPersist.Commit();
3344
                                    ReleaseCOMObjects(_LMLabelPersist);
3345
                                }
3346
                            }
3347
                        }
3348
                    }
3349
                }
3350
                else if (owner.GetType() == typeof(Line))
3351
                {
3352
                    Line line = owner as Line;
3353
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3354
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
3355

    
3356
                    if (connectedLMConnector != null)
3357
                    {
3358
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3359
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3360
                        {
3361
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3362

    
3363
                            if (mapping != null)
3364
                            {
3365
                                double x = 0;
3366
                                double y = 0;
3367

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

    
3371
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3372
                                if (_LMLabelPersist != null)
3373
                                {
3374
                                    _LMLabelPersist.Commit();
3375
                                    ReleaseCOMObjects(_LMLabelPersist);
3376
                                }
3377
                            }
3378
                        }
3379
                    }
3380
                }
3381
            }
3382
            else
3383
            {
3384
                LMItemNote _LMItemNote = null;
3385
                LMAAttribute _LMAAttribute = null;
3386

    
3387
                double x = 0;
3388
                double y = 0;
3389
                double angle = text.ANGLE;
3390
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3391

    
3392
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3393
                _LMSymbol.Commit();
3394
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3395
                _LMItemNote.Commit();
3396
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3397
                _LMAAttribute.set_Value(text.VALUE);
3398
                _LMItemNote.Commit();
3399

    
3400
                if (_LMAAttribute != null)
3401
                    ReleaseCOMObjects(_LMAAttribute);
3402
                if (_LMItemNote != null)
3403
                    ReleaseCOMObjects(_LMItemNote);
3404
            }
3405
            if (_LMSymbol != null)
3406
                ReleaseCOMObjects(_LMSymbol);
3407
        }
3408

    
3409
        /// <summary>
3410
        /// Note Modeling
3411
        /// </summary>
3412
        /// <param name="note"></param>
3413
        private void NoteModeling(Note note)
3414
        {
3415
            LMSymbol _LMSymbol = null;
3416
            LMItemNote _LMItemNote = null;
3417
            LMAAttribute _LMAAttribute = null;
3418

    
3419
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
3420
            {
3421
                double x = 0;
3422
                double y = 0;
3423

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

    
3426
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3427
                _LMSymbol.Commit();
3428
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3429
                _LMItemNote.Commit();
3430
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3431
                _LMAAttribute.set_Value(note.VALUE);
3432
                _LMItemNote.Commit();
3433
            }
3434

    
3435
            if (_LMAAttribute != null)
3436
                ReleaseCOMObjects(_LMAAttribute);
3437
            if (_LMItemNote != null)
3438
                ReleaseCOMObjects(_LMItemNote);
3439
            if (_LMSymbol != null)
3440
                ReleaseCOMObjects(_LMSymbol);
3441
        }
3442

    
3443
        /// <summary>
3444
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
3445
        /// </summary>
3446
        /// <param name="x"></param>
3447
        /// <param name="y"></param>
3448
        /// <param name="originX"></param>
3449
        /// <param name="originY"></param>
3450
        /// <param name="SPPIDLabelLocation"></param>
3451
        /// <param name="location"></param>
3452
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
3453
        {
3454
            if (location == Location.None)
3455
            {
3456
                x = originX;
3457
                y = originY;
3458
            }
3459
            else
3460
            {
3461
                if (location.HasFlag(Location.Center))
3462
                {
3463
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
3464
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
3465
                }
3466

    
3467
                if (location.HasFlag(Location.Left))
3468
                    x = SPPIDLabelLocation.X1;
3469
                else if (location.HasFlag(Location.Right))
3470
                    x = SPPIDLabelLocation.X2;
3471

    
3472
                if (location.HasFlag(Location.Down))
3473
                    y = SPPIDLabelLocation.Y1;
3474
                else if (location.HasFlag(Location.Up))
3475
                    y = SPPIDLabelLocation.Y2;
3476
            }
3477
        }
3478

    
3479
        /// <summary>
3480
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
3481
        /// 1. Angle Valve
3482
        /// 2. 3개로 이루어진 Symbol Group
3483
        /// </summary>
3484
        /// <returns></returns>
3485
        private List<Symbol> GetPrioritySymbol()
3486
        {
3487
            DataTable symbolTable = document.SymbolTable;
3488
            // List에 순서대로 쌓는다.
3489
            List<Symbol> symbols = new List<Symbol>();
3490

    
3491
            // Angle Valve 부터
3492
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
3493
            {
3494
                if (!symbols.Contains(symbol))
3495
                {
3496
                    double originX = 0;
3497
                    double originY = 0;
3498

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

    
3503
                    SlopeType slopeType1 = SlopeType.None;
3504
                    SlopeType slopeType2 = SlopeType.None;
3505
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
3506
                    {
3507
                        double connectorX = 0;
3508
                        double connectorY = 0;
3509
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3510
                        if (slopeType1 == SlopeType.None)
3511
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3512
                        else
3513
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3514
                    }
3515

    
3516
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3517
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3518
                        symbols.Add(symbol);
3519
                }
3520
            }
3521

    
3522
            List<Symbol> tempSymbols = new List<Symbol>();
3523
            // Conn 갯수 기준
3524
            foreach (var item in document.SYMBOLS)
3525
            {
3526
                if (!symbols.Contains(item))
3527
                    tempSymbols.Add(item);
3528
            }
3529
            tempSymbols.Sort(SortSymbolPriority);
3530
            symbols.AddRange(tempSymbols);
3531

    
3532
            return symbols;
3533
        }
3534

    
3535
        private void SetPriorityLine()
3536
        {
3537
            document.LINES.Sort(SortLinePriority);
3538

    
3539
            int SortLinePriority(Line a, Line b)
3540
            {
3541
                // Branch 없는것부터
3542
                int branchRetval = CompareBranchLine(a, b);
3543
                if (branchRetval != 0)
3544
                {
3545
                    return branchRetval;
3546
                }
3547
                else
3548
                {
3549
                    // Symbol 연결 갯수
3550
                    int connSymbolRetval = CompareConnSymbol(a, b);
3551
                    if (connSymbolRetval != 0)
3552
                    {
3553
                        return connSymbolRetval;
3554
                    }
3555
                    else
3556
                    {
3557
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
3558
                        int connItemRetval = CompareConnItem(a, b);
3559
                        if (connItemRetval != 0)
3560
                        {
3561
                            return connItemRetval;
3562
                        }
3563
                        else
3564
                        {
3565
                            // ConnectedItem이 없는것
3566
                            int noneConnRetval = CompareNoneConn(a, b);
3567
                            if (noneConnRetval != 0)
3568
                            {
3569
                                return noneConnRetval;
3570
                            }
3571
                            else
3572
                            {
3573

    
3574
                            }
3575
                        }
3576
                    }
3577
                }
3578

    
3579
                return 0;
3580
            }
3581

    
3582
            int CompareConnSymbol(Line a, Line b)
3583
            {
3584
                List<Connector> connectorsA = a.CONNECTORS
3585
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3586
                    .ToList();
3587

    
3588
                List<Connector> connectorsB = b.CONNECTORS
3589
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3590
                    .ToList();
3591

    
3592
                // 오름차순
3593
                return connectorsB.Count.CompareTo(connectorsA.Count);
3594
            }
3595

    
3596
            int CompareConnItem(Line a, Line b)
3597
            {
3598
                List<Connector> connectorsA = a.CONNECTORS
3599
                    .Where(conn => conn.ConnectedObject != null && 
3600
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
3601
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
3602
                    .ToList();
3603

    
3604
                List<Connector> connectorsB = b.CONNECTORS
3605
                    .Where(conn => conn.ConnectedObject != null &&
3606
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
3607
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
3608
                    .ToList();
3609

    
3610
                // 오름차순
3611
                return connectorsB.Count.CompareTo(connectorsA.Count);
3612
            }
3613

    
3614
            int CompareBranchLine(Line a, Line b)
3615
            {
3616
                List<Connector> connectorsA = a.CONNECTORS
3617
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
3618
                    .ToList();
3619
                List<Connector> connectorsB = b.CONNECTORS
3620
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
3621
                    .ToList();
3622

    
3623
                // 내림차순
3624
                return connectorsA.Count.CompareTo(connectorsB.Count);
3625
            }
3626

    
3627
            int CompareNoneConn(Line a, Line b)
3628
            {
3629
                List<Connector> connectorsA = a.CONNECTORS
3630
                    .Where(conn => conn.ConnectedObject == null)
3631
                    .ToList();
3632

    
3633
                List<Connector> connectorsB = b.CONNECTORS
3634
                    .Where(conn => conn.ConnectedObject == null)
3635
                    .ToList();
3636

    
3637
                // 오름차순
3638
                return connectorsB.Count.CompareTo(connectorsA.Count);
3639
            }
3640
        }
3641

    
3642
        private void SortBranchLines()
3643
        {
3644
            NewBranchLines.Sort(SortBranchLine);
3645
            int SortBranchLine(Line a, Line b)
3646
            {
3647
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3648
                 x.ConnectedObject.GetType() == typeof(Line) &&
3649
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
3650
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3651

    
3652
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3653
                 x.ConnectedObject.GetType() == typeof(Line) &&
3654
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
3655
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3656

    
3657
                // 내림차순
3658
                return countA.CompareTo(countB);
3659
            }
3660
        }
3661

    
3662
        private static int SortSymbolPriority(Symbol a, Symbol b)
3663
        {
3664
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3665
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3666
            int retval = countB.CompareTo(countA);
3667
            if (retval != 0)
3668
                return retval;
3669
            else
3670
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
3671
        }
3672

    
3673
        /// <summary>
3674
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
3675
        /// </summary>
3676
        /// <param name="graphicOID"></param>
3677
        /// <param name="milliseconds"></param>
3678
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
3679
        {
3680
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
3681
            {
3682
                double minX = 0;
3683
                double minY = 0;
3684
                double maxX = 0;
3685
                double maxY = 0;
3686
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
3687
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
3688

    
3689
                Thread.Sleep(milliseconds);
3690
            }
3691
        }
3692

    
3693
        /// <summary>
3694
        /// ComObject를 Release
3695
        /// </summary>
3696
        /// <param name="objVars"></param>
3697
        public void ReleaseCOMObjects(params object[] objVars)
3698
        {
3699
            int intNewRefCount = 0;
3700
            foreach (object obj in objVars)
3701
            {
3702
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
3703
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
3704
            }
3705
        }
3706
    }
3707
}
클립보드 이미지 추가 (최대 크기: 500 MB)