프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (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 && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(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, symbol);
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
            if (_TargetItem != null)
1029
            {
1030
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1031
                double x1 = 0;
1032
                double y1 = 0;
1033
                double x2 = 0;
1034
                double y2 = 0;
1035
                symbol2d.Range(out x1, out y1, out x2, out y2);
1036
                range = new double[] { x1, y1, x2, y2 };
1037

    
1038
                foreach (var childSymbol in symbol.ChildSymbols)
1039
                    GetSPPIDChildSymbolRange(childSymbol, ref range);
1040

    
1041
                ReleaseCOMObjects(_TargetItem);
1042
            }
1043
        }
1044

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

    
1058
                tempRange[0] = Math.Min(tempRange[0], x1);
1059
                tempRange[1] = Math.Min(tempRange[1], y1);
1060
                tempRange[2] = Math.Max(tempRange[2], x2);
1061
                tempRange[3] = Math.Max(tempRange[3], y2);
1062

    
1063
                foreach (var childSymbol in symbol.ChildSymbols)
1064
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1065

    
1066
                ReleaseCOMObjects(_TargetItem);
1067
            }
1068

    
1069
            range = tempRange;
1070
        }
1071

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

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

    
1101
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1102
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1103

    
1104
            ReleaseCOMObjects(_ChildSymbol);
1105
        }
1106

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

    
1123
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1124
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1125
                ReleaseCOMObjects(_ChildSymbol);
1126
            }
1127
        }
1128

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

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

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

    
1166
                        //Leader 선 센터로
1167
                        if (_LMLabelPresist != null)
1168
                        {
1169
                            // Target Item에 Label의 Attribute Input
1170
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1171

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

    
1200
                                        if (result)
1201
                                            break;
1202
                                    }
1203

    
1204
                                    if (result)
1205
                                        break;
1206
                                }
1207
                            }
1208

    
1209
                            _LMLabelPresist.Commit();
1210
                            ReleaseCOMObjects(_LMLabelPresist);
1211
                        }
1212

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

    
1229
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1230
                        if (_LMLabelPresist != null)
1231
                        {
1232
                            _LMLabelPresist.Commit();
1233
                            ReleaseCOMObjects(_LMLabelPresist);
1234
                        }
1235
                        ReleaseCOMObjects(connectedLMConnector);
1236
                    }
1237

    
1238
                    foreach (var item in connectorVertices)
1239
                        if (item.Key != null)
1240
                            ReleaseCOMObjects(item.Key);
1241
                }
1242
            }
1243
        }
1244

    
1245
        /// <summary>
1246
        /// Equipment를 실제로 Modeling 메서드
1247
        /// </summary>
1248
        /// <param name="equipment"></param>
1249
        private void EquipmentModeling(Equipment equipment)
1250
        {
1251
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1252
                return;
1253

    
1254
            LMSymbol _LMSymbol = null;
1255
            LMSymbol targetItem = null;
1256
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1257
            double x = equipment.SPPID.ORIGINAL_X;
1258
            double y = equipment.SPPID.ORIGINAL_Y;
1259
            int mirror = 0;
1260
            double angle = equipment.ANGLE;
1261

    
1262
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1263

    
1264
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1265
            if (connector != null)
1266
            {
1267
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1268
                if (connEquipment != null)
1269
                {
1270
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1271
                        EquipmentModeling(connEquipment);
1272

    
1273
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1274
                    {
1275
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1276
                        if (targetItem != null)
1277
                        {
1278
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
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
            else
1296
            {
1297
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1298
            }
1299

    
1300
            if (_LMSymbol != null)
1301
            {
1302
                _LMSymbol.Commit();
1303
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1304
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1305
                ReleaseCOMObjects(_LMSymbol);
1306
            }
1307

    
1308
            if (targetItem != null)
1309
            {
1310
                ReleaseCOMObjects(targetItem);
1311
            }
1312

    
1313
            ReleaseCOMObjects(_LMSymbol);
1314
        }
1315

    
1316
        /// <summary>
1317
        /// 첫 진입점
1318
        /// </summary>
1319
        /// <param name="symbol"></param>
1320
        private void SymbolModelingBySymbol(Symbol symbol)
1321
        {
1322
            SymbolModeling(symbol, null);
1323
            List<object> endObjects = new List<object>();
1324
            endObjects.Add(symbol);
1325

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

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

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

    
1404
                                    // Range 겹치는지 확인해야함
1405
                                    double[] prevRange = null;
1406
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1407
                                    double[] groupRange = null;
1408
                                    GetSPPIDSymbolRange(group, ref groupRange);
1409

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

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

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

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

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

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

    
1505
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1506
            if (_LMSymbol != null)
1507
            {
1508
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1509
                foreach (var item in childSymbol.ChildSymbols)
1510
                    CreateChildSymbol(item, _LMSymbol, parent);
1511
            }
1512
            else
1513
                Log.Write("Fail Child Symbol Modeling UID : " + parent.UID);
1514

    
1515

    
1516
            ReleaseCOMObjects(_LMSymbol);
1517
        }
1518

    
1519
        private void NewLineModeling(Line line, bool isBranchModeling = false)
1520
        {
1521
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (NewBranchLines.Contains(line) && !isBranchModeling))
1522
                return;
1523

    
1524
            List<Line> group = new List<Line>();
1525
            GetConnectedLineGroup(line, group);
1526
            LineCoordinateCorrection(group);
1527

    
1528
            foreach (var groupLine in group)
1529
            {
1530
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1531
                {
1532
                    NewBranchLines.Add(groupLine);
1533
                    continue;
1534
                }
1535

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

    
1585
                            placeRunInputs.AddPoint(x, y);
1586

    
1587
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1588
                            {
1589
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1590
                                    placeRunInputs.AddPoint(x, -0.1);
1591
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1592
                                    placeRunInputs.AddPoint(-0.1, y);
1593
                                else
1594
                                    placeRunInputs.AddPoint(x, -0.1);
1595
                            }
1596
                        }
1597
                    }
1598
                }
1599

    
1600
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1601
                if (_lMConnector != null)
1602
                {
1603
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1604
                    bool bRemodelingStart = false;
1605
                    if (_LMSymbolStart != null)
1606
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1607
                    bool bRemodelingEnd = false;
1608
                    if (_LMSymbolEnd != null)
1609
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1610

    
1611
                    if (bRemodelingStart || bRemodelingEnd)
1612
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1613

    
1614
                    FlowMarkModeling(groupLine);
1615
                    LineNumberModeling(groupLine);
1616

    
1617
                    ReleaseCOMObjects(_lMConnector);
1618
                }
1619

    
1620
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1621
                x.ConnectedObject != null &&
1622
                x.ConnectedObject.GetType() == typeof(Line) &&
1623
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1624
                .Select(x => x.ConnectedObject)
1625
                .ToList();
1626

    
1627
                foreach (var item in removeLines)
1628
                    RemoveLineForModeling(item as Line);
1629

    
1630
                if (_LMAItem != null)
1631
                    ReleaseCOMObjects(_LMAItem);
1632
                if (placeRunInputs != null)
1633
                    ReleaseCOMObjects(placeRunInputs);
1634
                if (_LMSymbolStart != null)
1635
                    ReleaseCOMObjects(_LMSymbolStart);
1636
                if (_LMSymbolEnd != null)
1637
                    ReleaseCOMObjects(_LMSymbolEnd);
1638

    
1639
                if (isBranchModeling && NewBranchLines.Contains(groupLine))
1640
                    NewBranchLines.Remove(groupLine);
1641
            }
1642
        }
1643

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

    
1672
                ReleaseCOMObjects(modelItem);
1673
            }
1674
        }
1675

    
1676
        private void GetConnectedLineGroup(Line line, List<Line> group)
1677
        {
1678
            if (!group.Contains(line))
1679
                group.Add(line);
1680
            foreach (var connector in line.CONNECTORS)
1681
            {
1682
                if (connector.ConnectedObject != null &&
1683
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1684
                    !group.Contains(connector.ConnectedObject) &&
1685
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
1686
                {
1687
                    Line connLine = connector.ConnectedObject as Line;
1688
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
1689
                        GetConnectedLineGroup(connLine, group);
1690
                }
1691
            }
1692
        }
1693

    
1694
        private void LineCoordinateCorrection(List<Line> group)
1695
        {
1696
            // 순서대로 전 Item 기준 정렬
1697
            LineCoordinateCorrectionByStart(group);
1698

    
1699
            // 역으로 심볼이 있을 경우 좌표 보정
1700
            LineCoordinateCorrectionForLastLine(group);
1701
        }
1702

    
1703
        private void LineCoordinateCorrectionByStart(List<Line> group)
1704
        {
1705
            for (int i = 0; i < group.Count; i++)
1706
            {
1707
                Line line = group[i];
1708
                if (i == 0)
1709
                {
1710
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1711
                    if (symbolConnector != null)
1712
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
1713
                }
1714
                else if (i != 0)
1715
                {
1716
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
1717
                }
1718
            }
1719
        }
1720

    
1721
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
1722
        {
1723
            Line checkLine = group[group.Count - 1];
1724
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1725
            if (lastSymbolConnector != null)
1726
            {
1727
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
1728
                for (int i = group.Count - 2; i >= 0; i--)
1729
                {
1730
                    Line line = group[i + 1];
1731
                    Line prevLine = group[i];
1732

    
1733
                    // 같으면 보정
1734
                    if (line.SlopeType == prevLine.SlopeType)
1735
                        LineCoordinateCorrectionByConnItem(prevLine, line);
1736
                    else
1737
                    {
1738
                        if (line.SlopeType == SlopeType.HORIZONTAL)
1739
                        {
1740
                            double prevX = 0;
1741
                            double prevY = 0;
1742
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1743
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
1744

    
1745
                            double x = 0;
1746
                            double y = 0;
1747
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1748
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
1749
                        }
1750
                        else if (line.SlopeType == SlopeType.VERTICAL)
1751
                        {
1752
                            double prevX = 0;
1753
                            double prevY = 0;
1754
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1755
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
1756

    
1757
                            double x = 0;
1758
                            double y = 0;
1759
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1760
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
1761
                        }
1762
                        break;
1763
                    }
1764
                }
1765
            }
1766
        }
1767

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

    
1787
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
1788
        }
1789

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

    
1814
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
1815
        {
1816
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1817
            int index = line.CONNECTORS.IndexOf(connector);
1818
            if (index == 0)
1819
            {
1820
                line.SPPID.START_X = x;
1821
                if (line.SlopeType == SlopeType.VERTICAL)
1822
                    line.SPPID.END_X = x;
1823
            }
1824
            else
1825
            {
1826
                line.SPPID.END_X = x;
1827
                if (line.SlopeType == SlopeType.VERTICAL)
1828
                    line.SPPID.START_X = x;
1829
            }
1830
        }
1831

    
1832
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
1833
        {
1834
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1835
            int index = line.CONNECTORS.IndexOf(connector);
1836
            if (index == 0)
1837
            {
1838
                line.SPPID.START_Y = y;
1839
                if (line.SlopeType == SlopeType.HORIZONTAL)
1840
                    line.SPPID.END_Y = y;
1841
            }
1842
            else
1843
            {
1844
                line.SPPID.END_Y = y;
1845
                if (line.SlopeType == SlopeType.HORIZONTAL)
1846
                    line.SPPID.START_Y = y;
1847
            }
1848
        }
1849

    
1850
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1851
        {
1852
            if (symbol != null)
1853
            {
1854
                string repID = symbol.AsLMRepresentation().Id;
1855
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1856
                string lineUID = line.UID;
1857

    
1858
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1859
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1860
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1861

    
1862
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
1863
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1864
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1865

    
1866
                if (startSpecBreak != null || startEndBreak != null)
1867
                    result = true;
1868
            }
1869
        }
1870

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

    
1900
            List<double[]> vertices = new List<double[]>();
1901
            for (int i = 1; i <= verticesCount; i++)
1902
            {
1903
                double x = 0;
1904
                double y = 0;
1905
                lineStringGeometry.GetVertex(i, ref x, ref y);
1906
                vertices.Add(new double[] { x, y });
1907
            }
1908

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

    
1925
                        placeRunInputs.AddPoint(points[0], points[1]);
1926
                    }
1927
                    else
1928
                    {
1929
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1]);
1930
                    }
1931
                }
1932
                // 마지막 심볼이 있고 마지막 좌표일 때
1933
                else if (endSymbol != null && i == vertices.Count - 1)
1934
                {
1935
                    if (bEnd)
1936
                    {
1937
                        placeRunInputs.AddPoint(points[0], points[1]);
1938

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

    
1962
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1963
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1964

    
1965
            ReleaseCOMObjects(placeRunInputs);
1966
            ReleaseCOMObjects(_LMAItem);
1967
            ReleaseCOMObjects(modelItem);
1968

    
1969
            if (newConnector != null)
1970
            {
1971
                if (startSymbol != null && bStart)
1972
                {
1973
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1974
                    placeRunInputs = new PlaceRunInputs();
1975
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1976
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1977
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1978
                    if (_LMConnector != null)
1979
                    {
1980
                        RemoveConnectorForReModelingLine(newConnector);
1981
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1982
                        ReleaseCOMObjects(_LMConnector);
1983
                    }
1984
                    ReleaseCOMObjects(placeRunInputs);
1985
                    ReleaseCOMObjects(_LMAItem);
1986
                }
1987

    
1988
                if (endSymbol != null && bEnd)
1989
                {
1990
                    if (startSymbol != null)
1991
                    {
1992
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1993
                        newConnector = dicVertices.First().Key;
1994
                    }
1995

    
1996
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1997
                    placeRunInputs = new PlaceRunInputs();
1998
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1999
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2000
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2001
                    if (_LMConnector != null)
2002
                    {
2003
                        RemoveConnectorForReModelingLine(newConnector);
2004
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
2005
                        ReleaseCOMObjects(_LMConnector);
2006
                    }
2007
                    ReleaseCOMObjects(placeRunInputs);
2008
                    ReleaseCOMObjects(_LMAItem);
2009
                }
2010

    
2011
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2012
                ReleaseCOMObjects(newConnector);
2013
            }
2014

    
2015
            ReleaseCOMObjects(modelItem);
2016
        }
2017

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

    
2040
                    if (result)
2041
                        break;
2042
                }
2043
            }
2044
            foreach (var item in dicVertices)
2045
                ReleaseCOMObjects(item.Key);
2046
        }
2047

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

    
2073
                            if (child != null)
2074
                                break;
2075
                        }
2076

    
2077
                        if (child != null)
2078
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2079
                    }
2080

    
2081
                    break;
2082
                }
2083
            }
2084

    
2085
            return _LMSymbol;
2086
        }
2087

    
2088
        /// <summary>
2089
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2090
        /// </summary>
2091
        /// <param name="item"></param>
2092
        /// <param name="connector"></param>
2093
        /// <returns></returns>
2094
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2095
        {
2096
            foreach (var childSymbol in item.ChildSymbols)
2097
            {
2098
                if (childSymbol.Connectors.Contains(connector))
2099
                    return childSymbol;
2100
                else
2101
                    return GetChildSymbolByConnector(childSymbol, connector);
2102
            }
2103

    
2104
            return null;
2105
        }
2106

    
2107
        /// <summary>
2108
        /// EndBreak 모델링 메서드
2109
        /// </summary>
2110
        /// <param name="endBreak"></param>
2111
        private void EndBreakModeling(EndBreak endBreak)
2112
        {
2113
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2114
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2115
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2116

    
2117
            if (targetLMConnector != null)
2118
            {
2119
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2120
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2121
                if (_LmLabelPersist != null)
2122
                {
2123
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2124
                    if (_LmLabelPersist.ModelItemObject != null)
2125
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2126
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2127
                    ReleaseCOMObjects(_LmLabelPersist);
2128
                }
2129
                ReleaseCOMObjects(targetLMConnector);
2130
            }
2131
        }
2132

    
2133
        private LMConnector ReModelingLMConnector(LMConnector connector)
2134
        {
2135
            string symbolPath = string.Empty;
2136
            #region get symbol path
2137
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2138
            foreach (LMRepresentation rep in modelItem.Representations)
2139
            {
2140
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2141
                {
2142
                    symbolPath = rep.get_FileName();
2143
                    break;
2144
                }
2145
            }
2146
            #endregion
2147

    
2148
            LMConnector newConnector = null;
2149
            dynamic OID = connector.get_GraphicOID().ToString();
2150
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2151
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2152
            int verticesCount = lineStringGeometry.VertexCount;
2153
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2154
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2155

    
2156
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2157
            {
2158
                double[] vertices = null;
2159
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2160
                double x = 0;
2161
                double y = 0;
2162
                lineStringGeometry.GetVertex(1, ref x, ref y);
2163

    
2164
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2165
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2166

    
2167
                string flowDirection = string.Empty;
2168
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2169
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2170
                    flowDirection = flowAttribute.get_Value().ToString();
2171

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

    
2189
                for (int i = 0; i < vertices.Count; i++)
2190
                {
2191
                    double[] points = vertices[i];
2192
                    if (i == 0)
2193
                    {
2194
                        if (connector.ConnectItem1SymbolObject != null)
2195
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
2196
                        else
2197
                            placeRunInputs.AddPoint(points[0], points[1]);
2198
                    }
2199
                    else if (i == vertices.Count - 1)
2200
                    {
2201
                        if (connector.ConnectItem2SymbolObject != null)
2202
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
2203
                        else
2204
                            placeRunInputs.AddPoint(points[0], points[1]);
2205
                    }
2206
                    else
2207
                        placeRunInputs.AddPoint(points[0], points[1]);
2208
                }
2209

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

    
2212
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2213
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2214

    
2215
                foreach (var line in lines)
2216
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
2217
            }
2218

    
2219

    
2220
            return newConnector;
2221
        }
2222

    
2223
        /// <summary>
2224
        /// SpecBreak Modeling 메서드
2225
        /// </summary>
2226
        /// <param name="specBreak"></param>
2227
        private void SpecBreakModeling(SpecBreak specBreak)
2228
        {
2229
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2230
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2231

    
2232
            if (upStreamObj != null &&
2233
                downStreamObj != null)
2234
            {
2235
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2236

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

    
2248
                            if (_LmLabelPersist != null)
2249
                            {
2250
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2251
                                if (_LmLabelPersist.ModelItemObject != null)
2252
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2253
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2254
                                ReleaseCOMObjects(_LmLabelPersist);
2255
                            }
2256
                        }
2257
                    }
2258
                    ReleaseCOMObjects(targetLMConnector);
2259
                }
2260
            }
2261
        }
2262

    
2263
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2264
        {
2265
            LMConnector targetConnector = null;
2266
            Symbol targetSymbol = targetObj as Symbol;
2267
            Symbol connectedSymbol = connectedObj as Symbol;
2268
            Line targetLine = targetObj as Line;
2269
            Line connectedLine = connectedObj as Line;
2270
            if (targetSymbol != null && connectedSymbol != null)
2271
            {
2272
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2273
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2274

    
2275
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2276
                {
2277
                    if (connector.get_ItemStatus() != "Active")
2278
                        continue;
2279

    
2280
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2281
                    {
2282
                        targetConnector = connector;
2283
                        break;
2284
                    }
2285
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2286
                    {
2287
                        targetConnector = connector;
2288
                        break;
2289
                    }
2290
                }
2291

    
2292
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2293
                {
2294
                    if (connector.get_ItemStatus() != "Active")
2295
                        continue;
2296

    
2297
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2298
                    {
2299
                        targetConnector = connector;
2300
                        break;
2301
                    }
2302
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2303
                    {
2304
                        targetConnector = connector;
2305
                        break;
2306
                    }
2307
                }
2308

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

    
2317
                if (targetModelItem != null && connectedModelItem != null)
2318
                {
2319
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2320
                    {
2321
                        if (targetConnector != null)
2322
                            break;
2323

    
2324
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2325
                        {
2326
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2327

    
2328
                            if (IsConnected(_LMConnector, connectedModelItem))
2329
                                targetConnector = _LMConnector;
2330
                            else
2331
                                ReleaseCOMObjects(_LMConnector);
2332
                        }
2333
                    }
2334

    
2335
                    ReleaseCOMObjects(targetModelItem);
2336
                }
2337
            }
2338
            else
2339
            {
2340
                LMSymbol connectedLMSymbol = null;
2341
                if (connectedSymbol != null)
2342
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2343
                else if (targetSymbol != null)
2344
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2345
                else
2346
                {
2347

    
2348
                }
2349
                LMModelItem targetModelItem = null;
2350
                if (targetLine != null)
2351
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2352
                else if (connectedLine != null)
2353
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2354
                else
2355
                {
2356

    
2357
                }
2358
                if (connectedLMSymbol != null && targetModelItem != null)
2359
                {
2360
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2361
                    {
2362
                        if (connector.get_ItemStatus() != "Active")
2363
                            continue;
2364

    
2365
                        if (IsConnected(connector, targetModelItem))
2366
                        {
2367
                            targetConnector = connector;
2368
                            break;
2369
                        }
2370
                    }
2371

    
2372
                    if (targetConnector == null)
2373
                    {
2374
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2375
                        {
2376
                            if (connector.get_ItemStatus() != "Active")
2377
                                continue;
2378

    
2379
                            if (IsConnected(connector, targetModelItem))
2380
                            {
2381
                                targetConnector = connector;
2382
                                break;
2383
                            }
2384
                        }
2385
                    }
2386
                }
2387

    
2388
            }
2389

    
2390
            return targetConnector;
2391
        }
2392

    
2393
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2394
        {
2395
            bool result = false;
2396

    
2397
            foreach (LMRepresentation rep in modelItem.Representations)
2398
            {
2399
                if (result)
2400
                    break;
2401

    
2402
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2403
                {
2404
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2405

    
2406
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2407
                        connector.ConnectItem1SymbolObject != null &&
2408
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2409
                    {
2410
                        result = true;
2411
                        ReleaseCOMObjects(_LMConnector);
2412
                        break;
2413
                    }
2414
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2415
                        connector.ConnectItem2SymbolObject != null &&
2416
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2417
                    {
2418
                        result = true;
2419
                        ReleaseCOMObjects(_LMConnector);
2420
                        break;
2421
                    }
2422
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2423
                        connector.ConnectItem1SymbolObject != null &&
2424
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2425
                    {
2426
                        result = true;
2427
                        ReleaseCOMObjects(_LMConnector);
2428
                        break;
2429
                    }
2430
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2431
                        connector.ConnectItem2SymbolObject != null &&
2432
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2433
                    {
2434
                        result = true;
2435
                        ReleaseCOMObjects(_LMConnector);
2436
                        break;
2437
                    }
2438

    
2439
                    ReleaseCOMObjects(_LMConnector);
2440
                }
2441
            }
2442

    
2443

    
2444
            return result;
2445
        }
2446

    
2447
        /// <summary>
2448
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2449
        /// </summary>
2450
        /// <param name="modelItemID1"></param>
2451
        /// <param name="modelItemID2"></param>
2452
        private void JoinPipeRun(string modelItemID1, string modelItemID2)
2453
        {
2454
            LMModelItem modelItem1 = dataSource.GetModelItem(modelItemID1);
2455
            _LMAItem item1 = modelItem1.AsLMAItem();
2456
            LMModelItem modelItem2 = dataSource.GetModelItem(modelItemID2);
2457
            _LMAItem item2 = modelItem2.AsLMAItem();
2458

    
2459
            // item2가 item1으로 조인
2460
            _placement.PIDJoinRuns(ref item1, ref item2);
2461
            item1.Commit();
2462
            item2.Commit();
2463

    
2464
            string beforeID = string.Empty;
2465
            string afterID = string.Empty;
2466

    
2467
            if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
2468
            {
2469
                beforeID = modelItem2.Id;
2470
                afterID = modelItem1.Id;
2471
            }
2472
            else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
2473
            {
2474
                beforeID = modelItem1.Id;
2475
                afterID = modelItem2.Id;
2476
            }
2477
            else
2478
            {
2479
                throw new Exception("확인 필요한 케이스");
2480
            }
2481

    
2482
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
2483
            foreach (var line in lines)
2484
                line.SPPID.ModelItemId = afterID;
2485

    
2486
            ReleaseCOMObjects(modelItem1);
2487
            ReleaseCOMObjects(item1);
2488
            ReleaseCOMObjects(modelItem2);
2489
            ReleaseCOMObjects(item2);
2490
        }
2491

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

    
2506
                if (modelitemID != afterModelItemID)
2507
                {
2508
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
2509
                    foreach (var line in lines)
2510
                        line.SPPID.ModelItemId = afterModelItemID;
2511
                }
2512
                item.Commit();
2513
            }
2514

    
2515
            ReleaseCOMObjects(modelItem);
2516
            ReleaseCOMObjects(item);
2517
        }
2518

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

    
2537
        /// <summary>
2538
        /// PipeRun의 좌표를 가져오는 메서드
2539
        /// </summary>
2540
        /// <param name="modelId"></param>
2541
        /// <returns></returns>
2542
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2543
        {
2544
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2545
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2546

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

    
2571
                ReleaseCOMObjects(modelItem);
2572
            }
2573

    
2574
            return connectorVertices;
2575
        }
2576

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

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

    
2619
                    if ((x1 <= connX && x2 >= connX) ||
2620
                        (y1 <= connY && y2 >= connY))
2621
                    {
2622
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2623
                        if (length >= distance)
2624
                        {
2625
                            targetConnector = item.Key;
2626
                            length = distance;
2627
                        }
2628

    
2629
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2630
                        if (length >= distance)
2631
                        {
2632
                            targetConnector = item.Key;
2633
                            length = distance;
2634
                        }
2635
                    }
2636
                }
2637
            }
2638

    
2639
            // 못찾았을때.
2640
            length = double.MaxValue;
2641
            if (targetConnector == null)
2642
            {
2643
                foreach (var item in connectorVertices)
2644
                {
2645
                    List<double[]> points = item.Value;
2646

    
2647
                    foreach (double[] point in points)
2648
                    {
2649
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2650
                        if (length >= distance)
2651
                        {
2652
                            targetConnector = item.Key;
2653
                            length = distance;
2654
                        }
2655
                    }
2656
                }
2657
            }
2658

    
2659
            return targetConnector;
2660
        }
2661

    
2662
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
2663
        {
2664
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
2665

    
2666
            double length = double.MaxValue;
2667
            LMConnector targetConnector = null;
2668
            double[] resultPoint = null;
2669
            List<double[]> targetVertices = null;
2670

    
2671
            // Vertices 포인트에 제일 가까운곳
2672
            foreach (var item in vertices)
2673
            {
2674
                List<double[]> points = item.Value;
2675
                for (int i = 0; i < points.Count; i++)
2676
                {
2677
                    double[] point = points[i];
2678
                    double tempX = point[0];
2679
                    double tempY = point[1];
2680

    
2681
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
2682
                    if (length >= distance)
2683
                    {
2684
                        targetConnector = item.Key;
2685
                        length = distance;
2686
                        resultPoint = point;
2687
                        targetVertices = item.Value;
2688
                    }
2689
                }
2690
            }
2691

    
2692
            // Vertices Cross에 제일 가까운곳
2693
            foreach (var item in vertices)
2694
            {
2695
                List<double[]> points = item.Value;
2696
                for (int i = 0; i < points.Count - 1; i++)
2697
                {
2698
                    double[] point1 = points[i];
2699
                    double[] point2 = points[i + 1];
2700

    
2701
                    double maxLineX = Math.Max(point1[0], point2[0]);
2702
                    double minLineX = Math.Min(point1[0], point2[0]);
2703
                    double maxLineY = Math.Max(point1[1], point2[1]);
2704
                    double minLineY = Math.Min(point1[1], point2[1]);
2705

    
2706
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2707

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

    
2744
            foreach (var item in vertices)
2745
                if (item.Key != null && item.Key != targetConnector)
2746
                    ReleaseCOMObjects(item.Key);
2747

    
2748
            if (SPPIDUtil.IsBranchLine(line, targetLine))
2749
            {
2750
                double tempResultX = resultPoint[0];
2751
                double tempResultY = resultPoint[1];
2752
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
2753

    
2754
                GridSetting gridSetting = GridSetting.GetInstance();
2755

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

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

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

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

    
2855
                            if (connSymbol == null ||
2856
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2857
                                containZeroLength)
2858
                            {
2859
                                bool bCalcX = false;
2860
                                bool bCalcY = false;
2861
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2862
                                    bCalcX = true;
2863
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2864
                                    bCalcY = true;
2865
                                else
2866
                                {
2867
                                    bCalcX = true;
2868
                                    bCalcY = true;
2869
                                }
2870

    
2871
                                if (bCalcX)
2872
                                {
2873
                                    double nextX = targetVertices[i - 1][0];
2874
                                    double newX = 0;
2875
                                    if (nextX > tempX)
2876
                                    {
2877
                                        newX = tempX + gridSetting.Length;
2878
                                        if (newX > nextX)
2879
                                            newX = (point[0] + nextX) / 2;
2880
                                    }
2881
                                    else
2882
                                    {
2883
                                        newX = tempX - gridSetting.Length;
2884
                                        if (newX < nextX)
2885
                                            newX = (point[0] + nextX) / 2;
2886
                                    }
2887
                                    resultPoint = new double[] { newX, resultPoint[1] };
2888
                                }
2889

    
2890
                                if (bCalcY)
2891
                                {
2892
                                    double nextY = targetVertices[i - 1][1];
2893
                                    double newY = 0;
2894
                                    if (nextY > tempY)
2895
                                    {
2896
                                        newY = tempY + gridSetting.Length;
2897
                                        if (newY > nextY)
2898
                                            newY = (point[1] + nextY) / 2;
2899
                                    }
2900
                                    else
2901
                                    {
2902
                                        newY = tempY - gridSetting.Length;
2903
                                        if (newY < nextY)
2904
                                            newY = (point[1] + nextY) / 2;
2905
                                    }
2906
                                    resultPoint = new double[] { resultPoint[0], newY };
2907
                                }
2908
                            }
2909
                        }
2910
                        break;
2911
                    }
2912
                }
2913
            }
2914

    
2915
            x = resultPoint[0];
2916
            y = resultPoint[1];
2917

    
2918
            return targetConnector;
2919
        }
2920

    
2921
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
2922
        {
2923
            LMConnector result = null;
2924
            List<LMConnector> connectors = new List<LMConnector>();
2925
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
2926

    
2927
            if (modelItem != null)
2928
            {
2929
                foreach (LMRepresentation rep in modelItem.Representations)
2930
                {
2931
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2932
                        connectors.Add(dataSource.GetConnector(rep.Id));
2933
                }
2934

    
2935
                ReleaseCOMObjects(modelItem);
2936
            }
2937

    
2938
            if (connectors.Count == 1)
2939
                result = connectors[0];
2940
            else
2941
                foreach (var item in connectors)
2942
                    ReleaseCOMObjects(item);
2943

    
2944
            return result;
2945
        }
2946

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

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

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

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

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

    
3063
                                        }
3064
                                    }
3065
                                }
3066
                                _LMModelItem.Commit();
3067
                            }
3068
                            if (_LMModelItem != null)
3069
                                ReleaseCOMObjects(_LMModelItem);
3070

    
3071
                            break;
3072
                        }
3073
                    }
3074
                }
3075
            }
3076
        }
3077

    
3078
        /// <summary>
3079
        /// Symbol Attribute 입력 메서드
3080
        /// </summary>
3081
        /// <param name="item"></param>
3082
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3083
        {
3084

    
3085
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3086
            string sRep = null;
3087
            if (targetItem.GetType() == typeof(Symbol))
3088
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3089
            else if (targetItem.GetType() == typeof(Equipment))
3090
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3091

    
3092
            if (!string.IsNullOrEmpty(sRep))
3093
            {
3094
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3095
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3096
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3097

    
3098
                foreach (var item in targetAttributes)
3099
                {
3100
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3101
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3102
                    {
3103
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3104
                        if (_Attribute != null)
3105
                            _Attribute.set_Value(item.VALUE);
3106
                    }
3107
                }
3108
                _LMModelItem.Commit();
3109

    
3110
                ReleaseCOMObjects(_Attributes);
3111
                ReleaseCOMObjects(_LMModelItem);
3112
                ReleaseCOMObjects(_LMSymbol);
3113
            }
3114
        }
3115

    
3116
        /// <summary>
3117
        /// Input SpecBreak Attribute
3118
        /// </summary>
3119
        /// <param name="specBreak"></param>
3120
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3121
        {
3122
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3123
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3124

    
3125
            if (upStreamObj != null &&
3126
                downStreamObj != null)
3127
            {
3128
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3129

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

    
3147
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3148
                                }
3149
                            }
3150
                        }
3151
                    }
3152

    
3153
                    ReleaseCOMObjects(targetLMConnector);
3154
                }
3155
            }
3156

    
3157

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

    
3178
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3179
                    {
3180
                        if (connector.get_ItemStatus() != "Active")
3181
                            continue;
3182

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

    
3187
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3188
                    {
3189
                        if (connector.get_ItemStatus() != "Active")
3190
                            continue;
3191

    
3192
                        if (connector.Id != zeroLenthConnector.Id)
3193
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3194
                    }
3195

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

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

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

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

    
3214
                    ReleaseCOMObjects(zeroLenthConnector);
3215
                    ReleaseCOMObjects(upStreamLMSymbol);
3216
                    ReleaseCOMObjects(downStreamLMSymbol);
3217
                }
3218
                else if (upStreamSymbol != null && downStreamLine != null)
3219
                {
3220
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3221
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3222
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3223

    
3224
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3225
                    {
3226
                        if (connector.get_ItemStatus() != "Active")
3227
                            continue;
3228

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

    
3233
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3234
                    {
3235
                        if (connector.get_ItemStatus() != "Active")
3236
                            continue;
3237

    
3238
                        if (connector.Id != zeroLenthConnector.Id)
3239
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3240
                    }
3241

    
3242
                    ReleaseCOMObjects(zeroLenthConnector);
3243
                    ReleaseCOMObjects(upStreamLMSymbol);
3244
                }
3245
                else if (upStreamLine != null && downStreamSymbol != null)
3246
                {
3247
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3248
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3249
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3250

    
3251
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3252
                    {
3253
                        if (connector.get_ItemStatus() != "Active")
3254
                            continue;
3255

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

    
3260
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3261
                    {
3262
                        if (connector.get_ItemStatus() != "Active")
3263
                            continue;
3264

    
3265
                        if (connector.Id != zeroLenthConnector.Id)
3266
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3267
                    }
3268

    
3269
                    ReleaseCOMObjects(zeroLenthConnector);
3270
                    ReleaseCOMObjects(downStreamLMSymbol);
3271
                }
3272
            }
3273

    
3274
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3275
            {
3276
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3277
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3278
                {
3279
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3280
                    if (_LMAAttribute != null)
3281
                    {
3282
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3283
                            _LMAAttribute.set_Value(value);
3284
                        else if (_LMAAttribute.get_Value() != value)
3285
                            _LMAAttribute.set_Value(value);
3286
                    }
3287

    
3288
                    _LMModelItem.Commit();
3289
                }
3290
                if (_LMModelItem != null)
3291
                    ReleaseCOMObjects(_LMModelItem);
3292
            }
3293

    
3294
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3295
            {
3296
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3297
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3298
                {
3299
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3300
                    if (_LMAAttribute != null)
3301
                    {
3302
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3303
                            _LMAAttribute.set_Value(value);
3304
                        else if (_LMAAttribute.get_Value() != value)
3305
                            _LMAAttribute.set_Value(value);
3306
                    }
3307

    
3308
                    _LMModelItem.Commit();
3309
                }
3310
                if (_LMModelItem != null)
3311
                    ReleaseCOMObjects(_LMModelItem);
3312
            }
3313
            #endregion
3314
        }
3315

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

    
3339
                            if (mapping != null)
3340
                            {
3341
                                double x = 0;
3342
                                double y = 0;
3343

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

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

    
3363
                    if (connectedLMConnector != null)
3364
                    {
3365
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3366
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3367
                        {
3368
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3369

    
3370
                            if (mapping != null)
3371
                            {
3372
                                double x = 0;
3373
                                double y = 0;
3374

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

    
3378
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3379
                                if (_LMLabelPersist != null)
3380
                                {
3381
                                    _LMLabelPersist.Commit();
3382
                                    ReleaseCOMObjects(_LMLabelPersist);
3383
                                }
3384
                            }
3385
                        }
3386
                    }
3387
                }
3388
            }
3389
            else
3390
            {
3391
                LMItemNote _LMItemNote = null;
3392
                LMAAttribute _LMAAttribute = null;
3393

    
3394
                double x = 0;
3395
                double y = 0;
3396
                double angle = text.ANGLE;
3397
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3398

    
3399
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3400
                _LMSymbol.Commit();
3401
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3402
                _LMItemNote.Commit();
3403
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3404
                _LMAAttribute.set_Value(text.VALUE);
3405
                _LMItemNote.Commit();
3406

    
3407
                if (_LMAAttribute != null)
3408
                    ReleaseCOMObjects(_LMAAttribute);
3409
                if (_LMItemNote != null)
3410
                    ReleaseCOMObjects(_LMItemNote);
3411
            }
3412
            if (_LMSymbol != null)
3413
                ReleaseCOMObjects(_LMSymbol);
3414
        }
3415

    
3416
        /// <summary>
3417
        /// Note Modeling
3418
        /// </summary>
3419
        /// <param name="note"></param>
3420
        private void NoteModeling(Note note)
3421
        {
3422
            LMSymbol _LMSymbol = null;
3423
            LMItemNote _LMItemNote = null;
3424
            LMAAttribute _LMAAttribute = null;
3425

    
3426
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
3427
            {
3428
                double x = 0;
3429
                double y = 0;
3430

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

    
3433
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3434
                _LMSymbol.Commit();
3435
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3436
                _LMItemNote.Commit();
3437
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3438
                _LMAAttribute.set_Value(note.VALUE);
3439
                _LMItemNote.Commit();
3440
            }
3441

    
3442
            if (_LMAAttribute != null)
3443
                ReleaseCOMObjects(_LMAAttribute);
3444
            if (_LMItemNote != null)
3445
                ReleaseCOMObjects(_LMItemNote);
3446
            if (_LMSymbol != null)
3447
                ReleaseCOMObjects(_LMSymbol);
3448
        }
3449

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

    
3474
                if (location.HasFlag(Location.Left))
3475
                    x = SPPIDLabelLocation.X1;
3476
                else if (location.HasFlag(Location.Right))
3477
                    x = SPPIDLabelLocation.X2;
3478

    
3479
                if (location.HasFlag(Location.Down))
3480
                    y = SPPIDLabelLocation.Y1;
3481
                else if (location.HasFlag(Location.Up))
3482
                    y = SPPIDLabelLocation.Y2;
3483
            }
3484
        }
3485

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

    
3498
            // Angle Valve 부터
3499
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
3500
            {
3501
                if (!symbols.Contains(symbol))
3502
                {
3503
                    double originX = 0;
3504
                    double originY = 0;
3505

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

    
3510
                    SlopeType slopeType1 = SlopeType.None;
3511
                    SlopeType slopeType2 = SlopeType.None;
3512
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
3513
                    {
3514
                        double connectorX = 0;
3515
                        double connectorY = 0;
3516
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3517
                        if (slopeType1 == SlopeType.None)
3518
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3519
                        else
3520
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3521
                    }
3522

    
3523
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3524
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3525
                        symbols.Add(symbol);
3526
                }
3527
            }
3528

    
3529
            List<Symbol> tempSymbols = new List<Symbol>();
3530
            // Conn 갯수 기준
3531
            foreach (var item in document.SYMBOLS)
3532
            {
3533
                if (!symbols.Contains(item))
3534
                    tempSymbols.Add(item);
3535
            }
3536
            tempSymbols.Sort(SortSymbolPriority);
3537
            symbols.AddRange(tempSymbols);
3538

    
3539
            return symbols;
3540
        }
3541

    
3542
        private void SetPriorityLine()
3543
        {
3544
            document.LINES.Sort(SortLinePriority);
3545

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

    
3581
                            }
3582
                        }
3583
                    }
3584
                }
3585

    
3586
                return 0;
3587
            }
3588

    
3589
            int CompareConnSymbol(Line a, Line b)
3590
            {
3591
                List<Connector> connectorsA = a.CONNECTORS
3592
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3593
                    .ToList();
3594

    
3595
                List<Connector> connectorsB = b.CONNECTORS
3596
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3597
                    .ToList();
3598

    
3599
                // 오름차순
3600
                return connectorsB.Count.CompareTo(connectorsA.Count);
3601
            }
3602

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

    
3611
                List<Connector> connectorsB = b.CONNECTORS
3612
                    .Where(conn => conn.ConnectedObject != null &&
3613
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
3614
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
3615
                    .ToList();
3616

    
3617
                // 오름차순
3618
                return connectorsB.Count.CompareTo(connectorsA.Count);
3619
            }
3620

    
3621
            int CompareBranchLine(Line a, Line b)
3622
            {
3623
                List<Connector> connectorsA = a.CONNECTORS
3624
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
3625
                    .ToList();
3626
                List<Connector> connectorsB = b.CONNECTORS
3627
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
3628
                    .ToList();
3629

    
3630
                // 내림차순
3631
                return connectorsA.Count.CompareTo(connectorsB.Count);
3632
            }
3633

    
3634
            int CompareNoneConn(Line a, Line b)
3635
            {
3636
                List<Connector> connectorsA = a.CONNECTORS
3637
                    .Where(conn => conn.ConnectedObject == null)
3638
                    .ToList();
3639

    
3640
                List<Connector> connectorsB = b.CONNECTORS
3641
                    .Where(conn => conn.ConnectedObject == null)
3642
                    .ToList();
3643

    
3644
                // 오름차순
3645
                return connectorsB.Count.CompareTo(connectorsA.Count);
3646
            }
3647
        }
3648

    
3649
        private void SortBranchLines()
3650
        {
3651
            NewBranchLines.Sort(SortBranchLine);
3652
            int SortBranchLine(Line a, Line b)
3653
            {
3654
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3655
                 x.ConnectedObject.GetType() == typeof(Line) &&
3656
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
3657
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3658

    
3659
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3660
                 x.ConnectedObject.GetType() == typeof(Line) &&
3661
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
3662
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3663

    
3664
                // 내림차순
3665
                return countA.CompareTo(countB);
3666
            }
3667
        }
3668

    
3669
        private static int SortSymbolPriority(Symbol a, Symbol b)
3670
        {
3671
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3672
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3673
            int retval = countB.CompareTo(countA);
3674
            if (retval != 0)
3675
                return retval;
3676
            else
3677
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
3678
        }
3679

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

    
3696
                Thread.Sleep(milliseconds);
3697
            }
3698
        }
3699

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