프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ bd1985ec

이력 | 보기 | 이력해설 | 다운로드 (219 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 : IDisposable
28
    {
29
        Placement _placement;
30
        LMADataSource dataSource;
31
        string drawingID;
32
        dynamic newDrawing;
33
        dynamic application;
34
        bool closeDocument;
35
        Ingr.RAD2D.Application radApp;
36
        SPPID_Document document;
37
        ETCSetting _ETCSetting;
38

    
39
        public string DocumentLabelText { get; set; }
40

    
41
        List<Line> BranchLines = new List<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, bool closeDocument)
48
        {
49
            application = Interaction.GetObject("", "PIDAutomation.Application");
50
            WrapperApplication wApp = new WrapperApplication(application.Application);
51
            radApp = wApp.RADApplication;
52

    
53
            this.closeDocument = closeDocument;
54
            this.document = document;
55
            this._ETCSetting = ETCSetting.GetInstance();
56
        }
57

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

    
70
                }
71
            }
72
        }
73

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

    
86
                if (CreateDocument(ref drawingNumber, ref drawingName) && DocumentCoordinateCorrection())
87
                {
88
                    Log.Write("Start Modeling");
89
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
90
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
91
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 20);
92
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
93

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

    
127
                    // Result Logging
128
                    document.CheckModelingResult();
129
                }
130
            }
131
            catch (Exception ex)
132
            {
133
                if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible)
134
                {
135
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
136
                    SplashScreenManager.CloseForm(false);
137
                    Log.Write("\r\n");
138
                }
139
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
140
            }
141
            finally
142
            {
143
                Project_DB.InsertDrawingInfoAndOPCInfo(document.PATH, drawingNumber, drawingName, document);
144
                if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible)
145
                {
146
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
147
                    SplashScreenManager.CloseForm(false);
148
                    Log.Write("\r\n");
149
                }
150
                Thread.Sleep(1000);
151

    
152
                Log.Write("End Modeling");
153
                radApp.ActiveWindow.Fit();
154

    
155
                ReleaseCOMObjects(application);
156
                application = null;
157
                if (radApp.ActiveDocument != null)
158
                {
159
                    if (closeDocument && newDrawing != null)
160
                    {
161
                        newDrawing.Save();
162
                        newDrawing.CloseDrawing(true);
163
                        ReleaseCOMObjects(newDrawing);
164
                        newDrawing = null;
165
                    }
166
                    else if (newDrawing == null)
167
                    {
168
                        Log.Write("error document");
169
                    }
170
                }
171

    
172
                ReleaseCOMObjects(dataSource);
173
                dataSource = null;
174
                ReleaseCOMObjects(_placement);
175
                _placement = null;
176

    
177
                Thread.Sleep(1000);
178
            }
179
        }
180

    
181
        private void RunEquipmentModeling()
182
        {
183
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
184
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
185
            foreach (Equipment item in document.Equipments)
186
            {
187
                try
188
                {
189
                    EquipmentModeling(item);
190
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
191
                }
192
                catch (Exception ex)
193
                {
194
                    Log.Write("Error in EquipmentModeling");
195
                    Log.Write("UID : " + item.UID);
196
                    Log.Write(ex.Message);
197
                    Log.Write(ex.StackTrace);
198
                }
199
            }
200
        }
201

    
202
        private void RunSymbolModeling()
203
        {
204
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
205
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
206
            prioritySymbols = GetPrioritySymbol();
207
            foreach (var item in prioritySymbols)
208
            {
209
                try
210
                {
211
                    SymbolModelingBySymbol(item);
212
                }
213
                catch (Exception ex)
214
                {
215
                    Log.Write("Error in SymbolModelingByPriority");
216
                    Log.Write("UID : " + item.UID);
217
                    Log.Write(ex.Message);
218
                    Log.Write(ex.StackTrace);
219
                }
220
            }
221
        }
222
        private void RunLineModeling()
223
        {
224
            List<Line> AllLine = document.LINES.ToList();
225
            List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 &&
226
            !SPPIDUtil.IsBranchedLine(document, x));
227
            List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x));
228

    
229
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count);
230
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 1");
231

    
232
            SetPriorityLine(step1_Line);
233
            foreach (var item in step1_Line)
234
            {
235
                try
236
                {
237
                    NewLineModeling(item);
238
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
239
                }
240
                catch (Exception ex)
241
                {
242
                    Log.Write("Error in NewLineModeling");
243
                    Log.Write("UID : " + item.UID);
244
                    Log.Write(ex.Message);
245
                    Log.Write(ex.StackTrace);
246
                }
247
            }
248

    
249
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, BranchLines.Count);
250
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 2");
251
            int branchCount = BranchLines.Count;
252
            while (BranchLines.Count > 0)
253
            {
254
                try
255
                {
256
                    SortBranchLines();
257
                    Line item = BranchLines[0];
258
                    NewLineModeling(item, true);
259
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
260
                }
261
                catch (Exception ex)
262
                {
263
                    Log.Write("Error in NewLineModeling");
264
                    Log.Write("UID : " + BranchLines[0].UID);
265
                    Log.Write(ex.Message);
266
                    Log.Write(ex.StackTrace);
267
                    break;
268
                }
269
            }
270

    
271
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, stepLast_Line.Count);
272
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 3");
273
            foreach (var item in stepLast_Line)
274
            {
275
                try
276
                {
277
                    NewLineModeling(item);
278
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
279
                }
280
                catch (Exception ex)
281
                {
282
                    Log.Write("Error in NewLineModeling");
283
                    Log.Write("UID : " + item.UID);
284
                    Log.Write(ex.Message);
285
                    Log.Write(ex.StackTrace);
286
                }
287
            }
288
        }
289
        private void RunClearNominalDiameter()
290
        {
291
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.LINES.Count);
292
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Attribute");
293
            List<string> endClearModelItemID = new List<string>();
294
            for (int i = 0; i < document.LINES.Count; i++)
295
            {
296
                Line item = document.LINES[i];
297
                string modelItemID = item.SPPID.ModelItemId;
298
                if (!string.IsNullOrEmpty(modelItemID))
299
                {
300
                    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
301
                    if (modelItem != null)
302
                    {
303
                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
304
                        if (attribute != null)
305
                            attribute.set_Value(DBNull.Value);
306

    
307
                        modelItem.Commit();
308
                        ReleaseCOMObjects(modelItem);
309
                        modelItem = null;
310
                    }
311
                }
312
                if (!endClearModelItemID.Contains(modelItemID))
313
                    endClearModelItemID.Add(modelItemID);
314
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
315
            }
316
            for (int i = 0; i < document.SYMBOLS.Count; i++)
317
            {
318
                Symbol item = document.SYMBOLS[i];
319
                string repID = item.SPPID.RepresentationId;
320
                string modelItemID = item.SPPID.ModelItemID;
321
                if (!string.IsNullOrEmpty(modelItemID))
322
                {
323
                    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
324
                    if (modelItem != null)
325
                    {
326
                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
327
                        if (attribute != null)
328
                            attribute.set_Value(DBNull.Value);
329
                        int index = 1;
330
                        while (true)
331
                        {
332
                            attribute = modelItem.Attributes[string.Format("PipingPoint{0}.NominalDiameter", index)];
333
                            if (attribute != null)
334
                                attribute.set_Value(DBNull.Value);
335
                            else
336
                                break;
337
                            index++;
338
                        }
339
                        modelItem.Commit();
340
                        ReleaseCOMObjects(modelItem);
341
                        modelItem = null;
342
                    }
343
                }
344
                if (!string.IsNullOrEmpty(repID))
345
                {
346
                    LMSymbol symbol = dataSource.GetSymbol(repID);
347
                    if (symbol != null)
348
                    {
349
                        foreach (LMConnector connector in symbol.Connect1Connectors)
350
                        {
351
                            if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
352
                            {
353
                                endClearModelItemID.Add(connector.ModelItemID);
354
                                LMModelItem modelItem = connector.ModelItemObject;
355
                                if (modelItem != null)
356
                                {
357
                                    LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
358
                                    if (attribute != null)
359
                                        attribute.set_Value(DBNull.Value);
360

    
361
                                    modelItem.Commit();
362
                                    ReleaseCOMObjects(modelItem);
363
                                    modelItem = null;
364
                                }
365
                            }
366
                        }
367
                        foreach (LMConnector connector in symbol.Connect2Connectors)
368
                        {
369
                            if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
370
                            {
371
                                endClearModelItemID.Add(connector.ModelItemID);
372
                                LMModelItem modelItem = connector.ModelItemObject;
373
                                if (modelItem != null)
374
                                {
375
                                    LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
376
                                    if (attribute != null)
377
                                        attribute.set_Value(DBNull.Value);
378

    
379
                                    modelItem.Commit();
380
                                    ReleaseCOMObjects(modelItem);
381
                                    modelItem = null;
382
                                }
383
                            }
384
                        }
385
                    }
386
                    ReleaseCOMObjects(symbol);
387
                    symbol = null;
388
                }
389
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
390
            }
391
        }
392
        private void RunClearValueInconsistancy()
393
        {
394
            int count = 1;
395
            bool loop = true;
396
            while (loop)
397
            {
398
                loop = false;
399
                LMAFilter filter = new LMAFilter();
400
                LMACriterion criterion = new LMACriterion();
401
                filter.ItemType = "Relationship";
402
                criterion.SourceAttributeName = "SP_DRAWINGID";
403
                criterion.Operator = "=";
404
                criterion.set_ValueAttribute(drawingID);
405
                filter.get_Criteria().Add(criterion);
406

    
407
                LMRelationships relationships = new LMRelationships();
408
                relationships.Collect(dataSource, Filter: filter);
409

    
410
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count);
411
                if (count > 1)
412
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null);
413
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count);
414
                foreach (LMRelationship relationship in relationships)
415
                {
416
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
417
                    {
418
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
419
                        {
420
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
421
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
422
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
423
                            if (modelItem1 != null)
424
                            {
425
                                string attrName = array[0];
426
                                if (attrName.Contains("PipingPoint"))
427
                                {
428
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
429
                                    int index = Convert.ToInt32(relationship.get_Item1Location());
430
                                    LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
431
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
432
                                    {
433
                                        loop = true;
434
                                        attribute1.set_Value(DBNull.Value);
435
                                    }
436
                                    attribute1 = null;
437
                                }
438
                                else
439
                                {
440
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
441
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
442
                                    {
443
                                        loop = true;
444
                                        attribute1.set_Value(DBNull.Value);
445
                                    }
446
                                    attribute1 = null;
447
                                }
448
                                modelItem1.Commit();
449
                            }
450
                            if (modelItem2 != null)
451
                            {
452
                                string attrName = array[1];
453
                                if (attrName.Contains("PipingPoint"))
454
                                {
455
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
456
                                    int index = Convert.ToInt32(relationship.get_Item2Location());
457
                                    LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
458
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
459
                                    {
460
                                        attribute2.set_Value(DBNull.Value);
461
                                        loop = true;
462
                                    }
463
                                    attribute2 = null;
464
                                }
465
                                else
466
                                {
467
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
468
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
469
                                    {
470
                                        attribute2.set_Value(DBNull.Value);
471
                                        loop = true;
472
                                    }
473
                                    attribute2 = null;
474
                                }
475
                                modelItem2.Commit();
476
                            }
477
                            ReleaseCOMObjects(modelItem1);
478
                            modelItem1 = null;
479
                            ReleaseCOMObjects(modelItem2);
480
                            modelItem2 = null;
481
                            inconsistency.Commit();
482
                        }
483
                        ReleaseCOMObjects(inconsistency);
484
                    }
485
                    relationship.Commit();
486
                    ReleaseCOMObjects(relationship);
487
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
488
                }
489
                ReleaseCOMObjects(filter);
490
                filter = null;
491
                ReleaseCOMObjects(criterion);
492
                criterion = null;
493
                ReleaseCOMObjects(relationships);
494
                relationships = null;
495
                count++;
496
            }
497
        }
498
        private void RunEndBreakModeling()
499
        {
500
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
501
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
502
            foreach (var item in document.EndBreaks)
503
                try
504
                {
505
                    EndBreakModeling(item);
506
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
507
                }
508
                catch (Exception ex)
509
                {
510
                    Log.Write("Error in EndBreakModeling");
511
                    Log.Write("UID : " + item.UID);
512
                    Log.Write(ex.Message);
513
                    Log.Write(ex.StackTrace);
514
                }
515
        }
516
        private void RunSpecBreakModeling()
517
        {
518
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
519
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
520
            foreach (var item in document.SpecBreaks)
521
                try
522
                {
523
                    SpecBreakModeling(item);
524
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
525
                }
526
                catch (Exception ex)
527
                {
528
                    Log.Write("Error in SpecBreakModeling");
529
                    Log.Write("UID : " + item.UID);
530
                    Log.Write(ex.Message);
531
                    Log.Write(ex.StackTrace);
532
                }
533
        }
534
        private void RunJoinRunForSameConnector()
535
        {
536
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
537
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1");
538
            foreach (var line in document.LINES)
539
            {
540
                foreach (var connector in line.CONNECTORS)
541
                {
542
                    if (connector.ConnectedObject != null &&
543
                        connector.ConnectedObject.GetType() == typeof(Line) &&
544
                        !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
545
                    {
546
                        Line connLine = connector.ConnectedObject as Line;
547
                        if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId &&
548
                            !string.IsNullOrEmpty(line.SPPID.ModelItemId) &&
549
                            !string.IsNullOrEmpty(connLine.SPPID.ModelItemId) &&
550
                            !SPPIDUtil.IsSegment(document, line, connLine))
551
                        {
552
                            string survivorId = string.Empty;
553
                            JoinRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId, ref survivorId);
554
                        }
555

    
556
                    }
557
                }
558
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
559
            }
560

    
561
            foreach (var line in document.LINES)
562
                line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId);
563
        }
564
        private void RunJoinRun()
565
        {
566
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
567
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 2");
568
            List<string> endModelID = new List<string>();
569
            foreach (var line in document.LINES)
570
            {
571
                if (!endModelID.Contains(line.SPPID.ModelItemId))
572
                {
573
                    while (!endModelID.Contains(line.SPPID.ModelItemId))
574
                    {
575
                        string survivorId = string.Empty;
576
                        JoinRunBySameType(line.SPPID.ModelItemId, ref survivorId);
577
                        if (string.IsNullOrEmpty(survivorId))
578
                        {
579
                            endModelID.Add(line.SPPID.ModelItemId);
580
                        }
581
                    }
582
                }
583
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
584
            }
585
        }
586
        private void RunLineNumberModeling()
587
        {
588
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
589
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Number Modeling");
590
            foreach (var item in document.LINENUMBERS)
591
            {
592
                LMLabelPersist label = dataSource.GetLabelPersist(item.SPPID.RepresentationId);
593
                if (label == null || (label != null && label.get_ItemStatus() != "Active"))
594
                {
595
                    ReleaseCOMObjects(label);
596
                    item.SPPID.RepresentationId = null;
597
                    LineNumberModeling(item);
598
                }
599
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
600
            }
601
        }
602
        private void RunFlowDirection()
603
        {
604
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 
605
                document.LINES.Count + ZeroLengthModelItemID.Count + ZeroLengthModelItemIDReverse.Count + ZeroLengthSymbolToSymbolModelItemID.Count);
606
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Check Flow Direction");
607
            foreach (var line in document.LINES)
608
            {
609
                if (!string.IsNullOrEmpty(line.SPPID.ModelItemId))
610
                {
611
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
612
                    if (modelItem != null && modelItem.get_ItemStatus() == "Active")
613
                    {
614
                        LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
615
                        if (attribute != null)
616
                        {
617
                            attribute.set_Value("End 1 is upstream (Inlet)");
618
                            modelItem.Commit();
619
                        }
620

    
621
                        SetFlowDirectionByLine(line.SPPID.ModelItemId);
622

    
623
                        ReleaseCOMObjects(modelItem);
624
                        modelItem = null;
625
                    }
626
                }
627

    
628
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
629
            }
630
            foreach (var modelId in ZeroLengthModelItemID)
631
            {
632
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
633
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
634
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
635
                {
636
                    attribute.set_Value("End 1 is upstream (Inlet)");
637
                    zeroLengthModelItem.Commit();
638
                }
639

    
640
                SetFlowDirectionByLine(modelId);
641

    
642
                ReleaseCOMObjects(zeroLengthModelItem);
643
                zeroLengthModelItem = null;
644

    
645
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
646
            }
647
            foreach (var modelId in ZeroLengthModelItemIDReverse)
648
            {
649
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
650
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
651
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
652
                {
653
                    attribute.set_Value("End 1 is downstream (Outlet)");
654
                    zeroLengthModelItem.Commit();
655
                }
656

    
657
                SetFlowDirectionByLine(modelId);
658

    
659
                ReleaseCOMObjects(zeroLengthModelItem);
660
                zeroLengthModelItem = null;
661

    
662
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
663
            }
664
            foreach (var modelId in ZeroLengthSymbolToSymbolModelItemID)
665
            {
666
                SetFlowDirectionByLine(modelId);
667
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
668
            }
669

    
670
            void SetFlowDirectionByLine(string lineModelItemID)
671
            {
672
                LMModelItem modelItem = dataSource.GetModelItem(lineModelItemID);
673
                if (modelItem != null && modelItem.get_ItemStatus() == "Active")
674
                {
675
                    LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
676
                    if (attribute != null && !DBNull.Value.Equals(attribute.get_Value()))
677
                    {
678
                        string sFlowDirection = attribute.get_Value().ToString();
679
                        foreach (LMRepresentation rep in modelItem.Representations)
680
                        {
681
                            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
682
                            {
683
                                LMConnector connector = dataSource.GetConnector(rep.Id);
684

    
685
                                foreach (LMRelationship relationship in connector.Relation1Relationships)
686
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
687
                                foreach (LMRelationship relationship in connector.Relation2Relationships)
688
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
689

    
690
                                ReleaseCOMObjects(connector);
691
                            }
692
                        }
693
                    }
694
                    ReleaseCOMObjects(modelItem);
695
                    modelItem = null;
696
                }
697

    
698
                void SetSymbolFlowDirectionByRelationShip(LMRelationship relationship, LMConnector connector, string sFlowDirection)
699
                {
700
                    // Item2가 Symbol
701
                    if (!DBNull.Value.Equals(relationship.Item1RepresentationID) && relationship.Item1RepresentationID == connector.Id &&
702
                        relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.get_RepresentationType() == "Symbol")
703
                    {
704
                        int symbolIndex = Convert.ToInt32(relationship.get_Item2Location());
705
                        int lineIndex = Convert.ToInt32(relationship.get_Item1Location());
706
                        LMModelItem symbolModelItem = relationship.Item2RepresentationObject.ModelItemObject;
707

    
708
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
709

    
710
                        symbolModelItem.Commit();
711
                        ReleaseCOMObjects(symbolModelItem);
712
                        symbolModelItem = null;
713
                    }
714
                    // Item1이 Symbol
715
                    else if (!DBNull.Value.Equals(relationship.Item2RepresentationID) && relationship.Item2RepresentationID == connector.Id &&
716
                            relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.get_RepresentationType() == "Symbol")
717
                    {
718
                        int symbolIndex = Convert.ToInt32(relationship.get_Item1Location());
719
                        int lineIndex = Convert.ToInt32(relationship.get_Item2Location());
720
                        LMModelItem symbolModelItem = relationship.Item1RepresentationObject.ModelItemObject;
721

    
722
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
723

    
724
                        symbolModelItem.Commit();
725
                        ReleaseCOMObjects(symbolModelItem);
726
                        symbolModelItem = null;
727
                    }
728
                }
729

    
730
                void SetSymbolFlowDirection(int lineIndex, int symbolIndex, string sFlowDirection, LMModelItem symbolModelItem)
731
                {
732
                    string attrName = "PipingPoint" + symbolIndex + ".FlowDirection";
733
                    LMAAttribute attribute = symbolModelItem.Attributes[attrName];
734
                    if (attribute != null)
735
                    {
736
                        if (lineIndex == 0 && sFlowDirection == "End 1 is upstream (Inlet)")
737
                            attribute.set_Value("End 1 is downstream (Outlet)");
738
                        else if (lineIndex == 0 && sFlowDirection == "End 1 is downstream (Outlet)")
739
                            attribute.set_Value("End 1 is upstream (Inlet)");
740
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is upstream (Inlet)")
741
                            attribute.set_Value("End 1 is upstream (Inlet)");
742
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is downstream (Outlet)")
743
                            attribute.set_Value("End 1 is downstream (Outlet)");
744
                    }
745
                }
746
            }
747
        }
748
        private void RunNoteModeling()
749
        {
750
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
751
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
752
            List<Note> correctList = new List<Note>();
753
            foreach (var item in document.NOTES)
754
                try
755
                {
756
                    NoteModeling(item, correctList);
757
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
758
                }
759
                catch (Exception ex)
760
                {
761
                    Log.Write("Error in NoteModeling");
762
                    Log.Write("UID : " + item.UID);
763
                    Log.Write(ex.Message);
764
                    Log.Write(ex.StackTrace);
765
                }
766

    
767
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
768
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Note");
769
            SortNote(correctList);
770
            List<Note> endList = new List<Note>();
771
            if (correctList.Count > 0)
772
                endList.Add(correctList[0]);
773
            foreach (var item in correctList)
774
                try
775
                {
776
                    if (!endList.Contains(item))
777
                        NoteCorrectModeling(item, endList);
778
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
779
                }
780
                catch (Exception ex)
781
                {
782
                    Log.Write("Error in NoteModeling");
783
                    Log.Write("UID : " + item.UID);
784
                    Log.Write(ex.Message);
785
                    Log.Write(ex.StackTrace);
786
                }
787
        }
788
        private void RunTextModeling()
789
        {
790
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
791
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
792
            List<Text> correctList = new List<Text>();
793
            foreach (var item in document.TEXTINFOS)
794
                try
795
                {
796
                    TextModeling(item, correctList);
797
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
798
                }
799
                catch (Exception ex)
800
                {
801
                    Log.Write("Error in TextModeling");
802
                    Log.Write("UID : " + item.UID);
803
                    Log.Write(ex.Message);
804
                    Log.Write(ex.StackTrace);
805
                }
806

    
807
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
808
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Text");
809
            SortText(correctList);
810
            List<Text> endList = new List<Text>();
811
            if (correctList.Count > 0)
812
                endList.Add(correctList[0]);
813
            foreach (var item in correctList)
814
                try
815
                {
816
                    if (!endList.Contains(item))
817
                        TextCorrectModeling(item, endList);
818
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
819
                }
820
                catch (Exception ex)
821
                {
822
                    Log.Write("Error in TextModeling");
823
                    Log.Write("UID : " + item.UID);
824
                    Log.Write(ex.Message);
825
                    Log.Write(ex.StackTrace);
826
                }
827
        }
828
        private void RunInputLineNumberAttribute()
829
        {
830
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
831
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
832
            List<string> endLine = new List<string>();
833
            foreach (var item in document.LINENUMBERS)
834
                try
835
                {
836
                    InputLineNumberAttribute(item, endLine);
837
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
838
                }
839
                catch (Exception ex)
840
                {
841
                    Log.Write("Error in InputLineNumberAttribute");
842
                    Log.Write("UID : " + item.UID);
843
                    Log.Write(ex.Message);
844
                    Log.Write(ex.StackTrace);
845
                }
846
        }
847
        private void RunInputSymbolAttribute()
848
        {
849
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
850
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
851
            foreach (var item in document.SYMBOLS)
852
                try
853
                {
854
                    InputSymbolAttribute(item, item.ATTRIBUTES);
855
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
856
                }
857
                catch (Exception ex)
858
                {
859
                    Log.Write("Error in InputSymbolAttribute");
860
                    Log.Write("UID : " + item.UID);
861
                    Log.Write(ex.Message);
862
                    Log.Write(ex.StackTrace);
863
                }
864
        }
865
        private void RunInputSpecBreakAttribute()
866
        {
867
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
868
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
869
            foreach (var item in document.SpecBreaks)
870
                try
871
                {
872
                    InputSpecBreakAttribute(item);
873
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
874
                }
875
                catch (Exception ex)
876
                {
877
                    Log.Write("Error in InputSpecBreakAttribute");
878
                    Log.Write("UID : " + item.UID);
879
                    Log.Write(ex.Message);
880
                    Log.Write(ex.StackTrace);
881
                }
882
        }
883
        private void RunLabelSymbolModeling()
884
        {
885
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
886
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
887
            foreach (var item in document.SYMBOLS)
888
                try
889
                {
890
                    LabelSymbolModeling(item);
891
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
892
                }
893
                catch (Exception ex)
894
                {
895
                    Log.Write("Error in LabelSymbolModeling");
896
                    Log.Write("UID : " + item.UID);
897
                    Log.Write(ex.Message);
898
                    Log.Write(ex.StackTrace);
899
                }
900
        }
901
        
902
        /// <summary>
903
        /// 도면 생성 메서드
904
        /// </summary>
905
        private bool CreateDocument(ref string drawingNumber, ref string drawingName)
906
        {
907
            Log.Write("------------------ Start create document ------------------");
908
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
909
            Log.Write("Drawing name : " + drawingName);
910
            Log.Write("Drawing number : " + drawingNumber);
911
            Thread.Sleep(1000);
912
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
913
            if (newDrawing != null)
914
            {
915
                document.SPPID_DrawingNumber = drawingNumber;
916
                document.SPPID_DrawingName = drawingName;
917
                Thread.Sleep(1000);
918
                radApp.ActiveWindow.Fit();
919
                Thread.Sleep(1000);
920
                radApp.ActiveWindow.Zoom = 2000;
921
                Thread.Sleep(2000);
922

    
923
                //current LMDrawing 가져오기
924
                LMAFilter filter = new LMAFilter();
925
                LMACriterion criterion = new LMACriterion();
926
                filter.ItemType = "Drawing";
927
                criterion.SourceAttributeName = "Name";
928
                criterion.Operator = "=";
929
                criterion.set_ValueAttribute(drawingName);
930
                filter.get_Criteria().Add(criterion);
931

    
932
                LMDrawings drawings = new LMDrawings();
933
                drawings.Collect(dataSource, Filter: filter);
934

    
935
                drawingID = ((dynamic)drawings).Nth(1).Id;
936
                ReleaseCOMObjects(filter);
937
                ReleaseCOMObjects(criterion);
938
                ReleaseCOMObjects(drawings);
939
                filter = null;
940
                criterion = null;
941
                drawings = null;
942
            }
943
            else
944
                Log.Write("Fail Create Drawing");
945

    
946
            if (newDrawing != null)
947
                return true;
948
            else
949
                return false;
950
        }
951

    
952
        /// <summary>
953
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
954
        /// </summary>
955
        /// <param name="drawingName"></param>
956
        /// <param name="drawingNumber"></param>
957
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
958
        {
959
            LMDrawings drawings = new LMDrawings();
960
            drawings.Collect(dataSource);
961

    
962
            List<string> drawingNameList = new List<string>();
963
            List<string> drawingNumberList = new List<string>();
964

    
965
            foreach (LMDrawing item in drawings)
966
            {
967
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
968
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
969
            }
970

    
971
            int nameLength = drawingName.Length;
972
            while (drawingNameList.Contains(drawingName))
973
            {
974
                if (nameLength == drawingName.Length)
975
                    drawingName += "-1";
976
                else
977
                {
978
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
979
                    drawingName = drawingName.Substring(0, nameLength + 1);
980
                    drawingName += ++index;
981
                }
982
            }
983

    
984
            int numberLength = drawingNumber.Length;
985
            while (drawingNameList.Contains(drawingNumber))
986
            {
987
                if (numberLength == drawingNumber.Length)
988
                    drawingNumber += "-1";
989
                else
990
                {
991
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
992
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
993
                    drawingNumber += ++index;
994
                }
995
            }
996
            ReleaseCOMObjects(drawings);
997
            drawings = null;
998
        }
999

    
1000
        /// <summary>
1001
        /// 도면 크기 구하는 메서드
1002
        /// </summary>
1003
        /// <returns></returns>
1004
        private bool DocumentCoordinateCorrection()
1005
        {
1006
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
1007
            {
1008
                Log.Write("Setting Drawing X, Drawing Y");
1009
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
1010
                Log.Write("Start coordinate correction");
1011
                document.CoordinateCorrection();
1012
                return true;
1013
            }
1014
            else
1015
            {
1016
                Log.Write("Need Drawing X, Y");
1017
                return false;
1018
            }
1019
        }
1020

    
1021
        /// <summary>
1022
        /// 심볼을 실제로 Modeling 메서드
1023
        /// </summary>
1024
        /// <param name="symbol">생성할 심볼</param>
1025
        /// <param name="targetSymbol">연결되어 있는 심볼</param>
1026
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
1027
        {
1028
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
1029
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
1030
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
1031
                return;
1032
            // 이미 모델링 됐을 경우
1033
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1034
                return;
1035

    
1036
            LMSymbol _LMSymbol = null;
1037

    
1038
            string mappingPath = symbol.SPPID.MAPPINGNAME;
1039
            double x = symbol.SPPID.ORIGINAL_X;
1040
            double y = symbol.SPPID.ORIGINAL_Y;
1041
            int mirror = 0;
1042
            double angle = symbol.ANGLE;
1043

    
1044
            // OPC 일경우 180도 일때 Mirror
1045
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
1046
                mirror = 1;
1047

    
1048
            // Mirror 계산
1049
            if (symbol.FLIP == 1)
1050
            {
1051
                mirror = 1;
1052
                angle += Math.PI;
1053
            }
1054

    
1055
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
1056
            {
1057
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);   /// RepresentationId로 SPPID 심볼을 찾음
1058
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
1059
                if (connector != null)
1060
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
1061

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

    
1064
                if (_LMSymbol != null && _TargetItem != null)
1065
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1066

    
1067
                ReleaseCOMObjects(_TargetItem);
1068
            }
1069
            else
1070
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1071

    
1072
            if (_LMSymbol != null)
1073
            {
1074
                _LMSymbol.Commit();
1075

    
1076
                // ConnCheck
1077
                List<string> ids = new List<string>();
1078
                foreach (LMConnector item in _LMSymbol.Connect1Connectors)
1079
                {
1080
                    if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id))
1081
                        ids.Add(item.Id);
1082
                    ReleaseCOMObjects(item);
1083
                }
1084
                foreach (LMConnector item in _LMSymbol.Connect2Connectors)
1085
                {
1086
                    if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id))
1087
                        ids.Add(item.Id);
1088
                    ReleaseCOMObjects(item);
1089
                }
1090

    
1091
                int createdSymbolCount = document.SYMBOLS.FindAll(i => i.CONNECTORS.Find(j => j.CONNECTEDITEM == symbol.UID) != null && !string.IsNullOrEmpty(i.SPPID.RepresentationId)).Count;
1092
                if (targetSymbol == null && ids.Count != createdSymbolCount)
1093
                {
1094
                    double currentX = _LMSymbol.get_XCoordinate();
1095
                    double currentY = _LMSymbol.get_YCoordinate();
1096

    
1097

    
1098
                }
1099

    
1100
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1101
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
1102
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1103

    
1104
                foreach (var item in symbol.ChildSymbols)
1105
                    CreateChildSymbol(item, _LMSymbol, symbol);
1106

    
1107
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
1108
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
1109

    
1110
                double[] range = null;
1111
                GetSPPIDSymbolRange(symbol, ref range);
1112
                symbol.SPPID.SPPID_Min_X = range[0];
1113
                symbol.SPPID.SPPID_Min_Y = range[1];
1114
                symbol.SPPID.SPPID_Max_X = range[2];
1115
                symbol.SPPID.SPPID_Max_Y = range[3];
1116

    
1117
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
1118
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
1119
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
1120
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
1121

    
1122
                ReleaseCOMObjects(_LMSymbol);
1123
            }
1124
        }
1125

    
1126
        private void RemoveSymbol(Symbol symbol)
1127
        {
1128
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1129
            {
1130
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1131
                if (_LMSymbol != null)
1132
                {
1133
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
1134
                    ReleaseCOMObjects(_LMSymbol);
1135
                }
1136
            }
1137

    
1138
            symbol.SPPID.RepresentationId = string.Empty;
1139
            symbol.SPPID.ModelItemID = string.Empty;
1140
            symbol.SPPID.SPPID_X = double.NaN;
1141
            symbol.SPPID.SPPID_Y = double.NaN;
1142
            symbol.SPPID.SPPID_Min_X = double.NaN;
1143
            symbol.SPPID.SPPID_Min_Y = double.NaN;
1144
            symbol.SPPID.SPPID_Max_X = double.NaN;
1145
            symbol.SPPID.SPPID_Max_Y = double.NaN;
1146
        }
1147

    
1148
        private void RemoveSymbol(List<Symbol> symbols)
1149
        {
1150
            foreach (var symbol in symbols)
1151
            {
1152
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1153
                {
1154
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1155
                    if (_LMSymbol != null)
1156
                    {
1157
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
1158
                        ReleaseCOMObjects(_LMSymbol);
1159
                    }
1160
                }
1161

    
1162
                symbol.SPPID.RepresentationId = string.Empty;
1163
                symbol.SPPID.ModelItemID = string.Empty;
1164
                symbol.SPPID.SPPID_X = double.NaN;
1165
                symbol.SPPID.SPPID_Y = double.NaN;
1166
                symbol.SPPID.SPPID_Min_X = double.NaN;
1167
                symbol.SPPID.SPPID_Min_Y = double.NaN;
1168
                symbol.SPPID.SPPID_Max_X = double.NaN;
1169
                symbol.SPPID.SPPID_Max_Y = double.NaN;
1170
            }
1171
        }
1172

    
1173
        /// <summary>
1174
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
1175
        /// </summary>
1176
        /// <param name="targetConnector"></param>
1177
        /// <param name="targetSymbol"></param>
1178
        /// <param name="x"></param>
1179
        /// <param name="y"></param>
1180
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
1181
        {
1182
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
1183

    
1184
            double[] range = null;
1185
            List<double[]> points = new List<double[]>();
1186
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
1187
            double x1 = range[0];
1188
            double y1 = range[1];
1189
            double x2 = range[2];
1190
            double y2 = range[3];
1191

    
1192
            // Origin 기준 Connector의 위치차이
1193
            double sceneX = 0;
1194
            double sceneY = 0;
1195
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
1196
            double originX = 0;
1197
            double originY = 0;
1198
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
1199
            double gapX = originX - sceneX;
1200
            double gapY = originY - sceneY;
1201

    
1202
            // SPPID Symbol과 ID2 심볼의 크기 차이
1203
            double sizeWidth = 0;
1204
            double sizeHeight = 0;
1205
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
1206
            if (sizeWidth == 0 || sizeHeight == 0)
1207
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
1208

    
1209
            double percentX = (x2 - x1) / sizeWidth;
1210
            double percentY = (y2 - y1) / sizeHeight;
1211

    
1212
            double SPPIDgapX = gapX * percentX;
1213
            double SPPIDgapY = gapY * percentY;
1214

    
1215
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
1216
            double distance = double.MaxValue;
1217
            double[] resultPoint;
1218
            foreach (var point in points)
1219
            {
1220
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
1221
                if (distance > result)
1222
                {
1223
                    distance = result;
1224
                    resultPoint = point;
1225
                    x = point[0];
1226
                    y = point[1];
1227
                }
1228
            }
1229

    
1230
            ReleaseCOMObjects(_TargetItem);
1231
        }
1232

    
1233
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
1234
        {
1235
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
1236
            if (index == 0)
1237
            {
1238
                x = targetLine.SPPID.START_X;
1239
                y = targetLine.SPPID.START_Y;
1240
            }
1241
            else
1242
            {
1243
                x = targetLine.SPPID.END_X;
1244
                y = targetLine.SPPID.END_Y;
1245
            }
1246
        }
1247

    
1248
        /// <summary>
1249
        /// SPPID Symbol의 Range를 구한다.
1250
        /// </summary>
1251
        /// <param name="symbol"></param>
1252
        /// <param name="range"></param>
1253
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
1254
        {
1255
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1256
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1257
            double x1 = 0;
1258
            double y1 = 0;
1259
            double x2 = 0;
1260
            double y2 = 0;
1261
            symbol2d.Range(out x1, out y1, out x2, out y2);
1262
            range = new double[] { x1, y1, x2, y2 };
1263

    
1264
            for (int i = 1; i < int.MaxValue; i++)
1265
            {
1266
                double connX = 0;
1267
                double connY = 0;
1268
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
1269
                    points.Add(new double[] { connX, connY });
1270
                else
1271
                    break;
1272
            }
1273

    
1274
            foreach (var childSymbol in symbol.ChildSymbols)
1275
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1276

    
1277
            ReleaseCOMObjects(_TargetItem);
1278
        }
1279

    
1280
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1281
        {
1282
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1283
            if (_TargetItem != null)
1284
            {
1285
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1286
                double x1 = 0;
1287
                double y1 = 0;
1288
                double x2 = 0;
1289
                double y2 = 0;
1290
                symbol2d.Range(out x1, out y1, out x2, out y2);
1291
                range = new double[] { x1, y1, x2, y2 };
1292

    
1293
                foreach (var childSymbol in symbol.ChildSymbols)
1294
                    GetSPPIDChildSymbolRange(childSymbol, ref range);
1295

    
1296
                ReleaseCOMObjects(_TargetItem);
1297
            }
1298
        }
1299

    
1300
        private void GetSPPIDSymbolRange(LMLabelPersist labelPersist, ref double[] range)
1301
        {
1302
            if (labelPersist != null)
1303
            {
1304
                Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject;
1305
                if (dependency != null)
1306
                {
1307
                    double x1 = 0;
1308
                    double y1 = 0;
1309
                    double x2 = 0;
1310
                    double y2 = 0;
1311
                    dependency.Range(out x1, out y1, out x2, out y2);
1312
                    range = new double[] { x1, y1, x2, y2 };
1313
                }
1314
            }
1315
        }
1316

    
1317
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1318
        {
1319
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1320
            foreach (var symbol in symbols)
1321
            {
1322
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1323
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1324
                double x1 = 0;
1325
                double y1 = 0;
1326
                double x2 = 0;
1327
                double y2 = 0;
1328
                symbol2d.Range(out x1, out y1, out x2, out y2);
1329

    
1330
                tempRange[0] = Math.Min(tempRange[0], x1);
1331
                tempRange[1] = Math.Min(tempRange[1], y1);
1332
                tempRange[2] = Math.Max(tempRange[2], x2);
1333
                tempRange[3] = Math.Max(tempRange[3], y2);
1334

    
1335
                foreach (var childSymbol in symbol.ChildSymbols)
1336
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1337

    
1338
                ReleaseCOMObjects(_TargetItem);
1339
            }
1340

    
1341
            range = tempRange;
1342
        }
1343

    
1344
        /// <summary>
1345
        /// Child Modeling 된 Symbol의 Range를 구한다.
1346
        /// </summary>
1347
        /// <param name="childSymbol"></param>
1348
        /// <param name="range"></param>
1349
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1350
        {
1351
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1352
            if (_ChildSymbol != null)
1353
            {
1354
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1355
                double x1 = 0;
1356
                double y1 = 0;
1357
                double x2 = 0;
1358
                double y2 = 0;
1359
                symbol2d.Range(out x1, out y1, out x2, out y2);
1360
                range[0] = Math.Min(range[0], x1);
1361
                range[1] = Math.Min(range[1], y1);
1362
                range[2] = Math.Max(range[2], x2);
1363
                range[3] = Math.Max(range[3], y2);
1364

    
1365
                for (int i = 1; i < int.MaxValue; i++)
1366
                {
1367
                    double connX = 0;
1368
                    double connY = 0;
1369
                    if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1370
                        points.Add(new double[] { connX, connY });
1371
                    else
1372
                        break;
1373
                }
1374

    
1375
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1376
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1377

    
1378
                ReleaseCOMObjects(_ChildSymbol);
1379
            }
1380
        }
1381

    
1382
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1383
        {
1384
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1385
            if (_ChildSymbol != null)
1386
            {
1387
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1388
                double x1 = 0;
1389
                double y1 = 0;
1390
                double x2 = 0;
1391
                double y2 = 0;
1392
                symbol2d.Range(out x1, out y1, out x2, out y2);
1393
                range[0] = Math.Min(range[0], x1);
1394
                range[1] = Math.Min(range[1], y1);
1395
                range[2] = Math.Max(range[2], x2);
1396
                range[3] = Math.Max(range[3], y2);
1397

    
1398
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1399
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1400
                ReleaseCOMObjects(_ChildSymbol);
1401
            }
1402
        }
1403

    
1404
        /// <summary>
1405
        /// Label Symbol Modeling
1406
        /// </summary>
1407
        /// <param name="symbol"></param>
1408
        private void LabelSymbolModeling(Symbol symbol)
1409
        {
1410
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1411
            {
1412
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1413
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1414
                    return;
1415
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1416

    
1417
                string symbolUID = itemAttribute.VALUE;
1418
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1419
                if (targetItem != null &&
1420
                    (targetItem.GetType() == typeof(Symbol) ||
1421
                    targetItem.GetType() == typeof(Equipment)))
1422
                {
1423
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1424
                    string sRep = null;
1425
                    if (targetItem.GetType() == typeof(Symbol))
1426
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1427
                    else if (targetItem.GetType() == typeof(Equipment))
1428
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1429
                    if (!string.IsNullOrEmpty(sRep))
1430
                    {
1431
                        // LEADER Line 검사
1432
                        bool leaderLine = false;
1433
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1434
                        if (symbolMapping != null)
1435
                            leaderLine = symbolMapping.LEADERLINE;
1436

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

    
1441
                        //Leader 선 센터로
1442
                        if (_LMLabelPresist != null)
1443
                        {
1444
                            // Target Item에 Label의 Attribute Input
1445
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1446

    
1447
                            string OID = _LMLabelPresist.get_GraphicOID().ToString();
1448
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1449
                            if (dependency != null)
1450
                            {
1451
                                bool result = false;
1452
                                foreach (var attributes in dependency.AttributeSets)
1453
                                {
1454
                                    foreach (var attribute in attributes)
1455
                                    {
1456
                                        string name = attribute.Name;
1457
                                        string value = attribute.GetValue().ToString();
1458
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1459
                                        {
1460
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1461
                                            {
1462
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1463
                                                {
1464
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1465
                                                    double prevX = _TargetItem.get_XCoordinate();
1466
                                                    double prevY = _TargetItem.get_YCoordinate();
1467
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1468
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1469
                                                    result = true;
1470
                                                    break;
1471
                                                }
1472
                                            }
1473
                                        }
1474

    
1475
                                        if (result)
1476
                                            break;
1477
                                    }
1478

    
1479
                                    if (result)
1480
                                        break;
1481
                                }
1482
                            }
1483

    
1484
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1485
                            _LMLabelPresist.Commit();
1486
                            ReleaseCOMObjects(_LMLabelPresist);
1487
                        }
1488

    
1489
                        ReleaseCOMObjects(_TargetItem);
1490
                    }
1491
                }
1492
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1493
                {
1494
                    Line targetLine = targetItem as Line;
1495
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1496
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1497
                    if (connectedLMConnector != null)
1498
                    {
1499
                        // LEADER Line 검사
1500
                        bool leaderLine = false;
1501
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1502
                        if (symbolMapping != null)
1503
                            leaderLine = symbolMapping.LEADERLINE;
1504

    
1505
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1506
                        if (_LMLabelPresist != null)
1507
                        {
1508
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1509
                            _LMLabelPresist.Commit();
1510
                            ReleaseCOMObjects(_LMLabelPresist);
1511
                        }
1512
                        ReleaseCOMObjects(connectedLMConnector);
1513
                    }
1514

    
1515
                    foreach (var item in connectorVertices)
1516
                        if (item.Key != null)
1517
                            ReleaseCOMObjects(item.Key);
1518
                }
1519
            }
1520
        }
1521

    
1522
        /// <summary>
1523
        /// Equipment를 실제로 Modeling 메서드
1524
        /// </summary>
1525
        /// <param name="equipment"></param>
1526
        private void EquipmentModeling(Equipment equipment)
1527
        {
1528
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1529
                return;
1530

    
1531
            LMSymbol _LMSymbol = null;
1532
            LMSymbol targetItem = null;
1533
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1534
            double x = equipment.SPPID.ORIGINAL_X;
1535
            double y = equipment.SPPID.ORIGINAL_Y;
1536
            int mirror = 0;
1537
            double angle = equipment.ANGLE;
1538

    
1539
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1540

    
1541
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1542
            if (connector != null)
1543
            {
1544
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1545
                if (connEquipment != null)
1546
                {
1547
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1548
                        EquipmentModeling(connEquipment);
1549

    
1550
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1551
                    {
1552
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1553
                        if (targetItem != null)
1554
                        {
1555
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1556
                        }
1557
                        else
1558
                        {
1559
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1560
                        }
1561
                    }
1562
                    else
1563
                    {
1564
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1565
                    }
1566
                }
1567
                else
1568
                {
1569
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1570
                }
1571
            }
1572
            else
1573
            {
1574
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1575
            }
1576

    
1577
            if (_LMSymbol != null)
1578
            {
1579
                _LMSymbol.Commit();
1580
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1581
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1582
                ReleaseCOMObjects(_LMSymbol);
1583
            }
1584

    
1585
            if (targetItem != null)
1586
            {
1587
                ReleaseCOMObjects(targetItem);
1588
            }
1589

    
1590
            ReleaseCOMObjects(_LMSymbol);
1591
        }
1592

    
1593
        /// <summary>
1594
        /// 첫 진입점
1595
        /// </summary>
1596
        /// <param name="symbol"></param>
1597
        private void SymbolModelingBySymbol(Symbol symbol)
1598
        {
1599
            SymbolModeling(symbol, null);   /// 심볼을 생성한다
1600
            List<object> endObjects = new List<object>();
1601
            endObjects.Add(symbol);
1602

    
1603
            /// 심볼에 연결되어 있는 항목들을 모델링한다
1604
            foreach (var connector in symbol.CONNECTORS)
1605
            {
1606
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1607
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1608
                {
1609
                    endObjects.Add(connItem);
1610
                    if (connItem.GetType() == typeof(Symbol))
1611
                    {
1612
                        Symbol connSymbol = connItem as Symbol;
1613
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1614
                        {
1615
                            SymbolModeling(connSymbol, symbol);
1616
                        }
1617
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1618
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1619
                    }
1620
                    else if (connItem.GetType() == typeof(Line))
1621
                    {
1622
                        Line connLine = connItem as Line;
1623
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1624
                    }
1625
                }
1626
            }
1627
        }
1628

    
1629
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1630
        {
1631
            foreach (var connector in symbol.CONNECTORS)
1632
            {
1633
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1634
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1635
                {
1636
                    if (!endObjects.Contains(connItem))
1637
                    {
1638
                        endObjects.Add(connItem);
1639
                        if (connItem.GetType() == typeof(Symbol))
1640
                        {
1641
                            Symbol connSymbol = connItem as Symbol;
1642
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1643
                            {
1644
                                SymbolModeling(connSymbol, symbol);
1645
                            }
1646
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1647
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1648
                        }
1649
                        else if (connItem.GetType() == typeof(Line))
1650
                        {
1651
                            Line connLine = connItem as Line;
1652
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1653
                        }
1654
                    }
1655
                }
1656
            }
1657
        }
1658

    
1659
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1660
        {
1661
            foreach (var connector in line.CONNECTORS)
1662
            {
1663
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1664
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1665
                {
1666
                    if (!endObjects.Contains(connItem))
1667
                    {
1668
                        endObjects.Add(connItem);
1669
                        if (connItem.GetType() == typeof(Symbol))
1670
                        {
1671
                            Symbol connSymbol = connItem as Symbol;
1672
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1673
                            {
1674
                                List<Symbol> group = new List<Symbol>();
1675
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1676
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1677
                                List<Symbol> endModelingGroup = new List<Symbol>();
1678
                                if (priority != null)
1679
                                {
1680
                                    SymbolGroupModeling(priority, group);
1681

    
1682
                                    // Range 겹치는지 확인해야함
1683
                                    double[] prevRange = null;
1684
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1685
                                    double[] groupRange = null;
1686
                                    GetSPPIDSymbolRange(group, ref groupRange);
1687

    
1688
                                    double distanceX = 0;
1689
                                    double distanceY = 0;
1690
                                    bool overlapX = false;
1691
                                    bool overlapY = false;
1692
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1693
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1694
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1695
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1696
                                    {
1697
                                        RemoveSymbol(group);
1698
                                        foreach (var _temp in group)
1699
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1700

    
1701
                                        SymbolGroupModeling(priority, group);
1702
                                    }
1703
                                }
1704
                                else
1705
                                {
1706
                                    SymbolModeling(connSymbol, null);
1707
                                    // Range 겹치는지 확인해야함
1708
                                    double[] prevRange = null;
1709
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1710
                                    double[] connRange = null;
1711
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1712

    
1713
                                    double distanceX = 0;
1714
                                    double distanceY = 0;
1715
                                    bool overlapX = false;
1716
                                    bool overlapY = false;
1717
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1718
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1719
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1720
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1721
                                    {
1722
                                        RemoveSymbol(connSymbol);
1723
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1724

    
1725
                                        SymbolModeling(connSymbol, null);
1726
                                    }
1727
                                }
1728
                            }
1729
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1730
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1731
                        }
1732
                        else if (connItem.GetType() == typeof(Line))
1733
                        {
1734
                            Line connLine = connItem as Line;
1735
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1736
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1737
                        }
1738
                    }
1739
                }
1740
            }
1741
        }
1742

    
1743
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1744
        {
1745
            List<Symbol> endModelingGroup = new List<Symbol>();
1746
            SymbolModeling(firstSymbol, null);
1747
            endModelingGroup.Add(firstSymbol);
1748
            while (endModelingGroup.Count != group.Count)
1749
            {
1750
                foreach (var _symbol in group)
1751
                {
1752
                    if (!endModelingGroup.Contains(_symbol))
1753
                    {
1754
                        foreach (var _connector in _symbol.CONNECTORS)
1755
                        {
1756
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
1757
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
1758
                            {
1759
                                SymbolModeling(_symbol, _connSymbol);
1760
                                endModelingGroup.Add(_symbol);
1761
                                break;
1762
                            }
1763
                        }
1764
                    }
1765
                }
1766
            }
1767
        }
1768

    
1769
        /// <summary>
1770
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
1771
        /// </summary>
1772
        /// <param name="childSymbol"></param>
1773
        /// <param name="parentSymbol"></param>
1774
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol, Symbol parent)
1775
        {
1776
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
1777
            double x1 = 0;
1778
            double x2 = 0;
1779
            double y1 = 0;
1780
            double y2 = 0;
1781
            symbol2d.Range(out x1, out y1, out x2, out y2);
1782

    
1783
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1784
            if (_LMSymbol != null)
1785
            {
1786
                _LMSymbol.Commit();
1787
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1788
                foreach (var item in childSymbol.ChildSymbols)
1789
                    CreateChildSymbol(item, _LMSymbol, parent);
1790
            }
1791

    
1792

    
1793
            ReleaseCOMObjects(_LMSymbol);
1794
        }
1795
        double index = 0;
1796
        private void NewLineModeling(Line line, bool isBranchModeling = false)
1797
        {
1798
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (BranchLines.Contains(line) && !isBranchModeling))
1799
                return;
1800

    
1801
            List<Line> group = new List<Line>();
1802
            GetConnectedLineGroup(line, group);
1803
            LineCoordinateCorrection(group);
1804

    
1805
            foreach (var groupLine in group)
1806
            {
1807
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1808
                {
1809
                    BranchLines.Add(groupLine);
1810
                    continue;
1811
                }
1812

    
1813
                bool diagonal = false;
1814
                if (groupLine.SlopeType != SlopeType.HORIZONTAL && groupLine.SlopeType != SlopeType.VERTICAL)
1815
                    diagonal = true;
1816
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
1817
                LMSymbol _LMSymbolStart = null;
1818
                LMSymbol _LMSymbolEnd = null;
1819
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1820
                foreach (var connector in groupLine.CONNECTORS)
1821
                {
1822
                    double x = 0;
1823
                    double y = 0;
1824
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
1825
                    if (connector.ConnectedObject == null)
1826
                    {
1827
                        placeRunInputs.AddPoint(x, y);
1828
                    }
1829
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
1830
                    {
1831
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
1832
                        GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y);
1833
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1834
                        {
1835
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
1836
                            if (_LMSymbolStart != null)
1837
                                placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal);
1838
                            else
1839
                                placeRunInputs.AddPoint(x, y);
1840
                        }
1841
                        else
1842
                        {
1843
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
1844
                            if (_LMSymbolEnd != null)
1845
                                placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal);
1846
                            else
1847
                                placeRunInputs.AddPoint(x, y);
1848
                        }
1849
                    }
1850
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
1851
                    {
1852
                        Line targetLine = connector.ConnectedObject as Line;
1853
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
1854
                        {
1855
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
1856
                            if (targetConnector != null)
1857
                            {
1858
                                placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal);
1859
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1860
                            }
1861
                            else
1862
                            {
1863
                                placeRunInputs.AddPoint( x, y);
1864
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1865
                            }
1866
                        }
1867
                        else
1868
                        {
1869
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1870
                            {
1871
                                index += 0.01;
1872
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1873
                                    placeRunInputs.AddPoint(x, -0.1 - index);
1874
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1875
                                    placeRunInputs.AddPoint(-0.1 - index, y);
1876
                                else
1877
                                {
1878
                                    Line nextLine = groupLine.CONNECTORS[0].ConnectedObject as Line;
1879
                                    if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45)
1880
                                        placeRunInputs.AddPoint(-0.1 - index, y);
1881
                                    else
1882
                                        placeRunInputs.AddPoint(x, -0.1 - index);
1883
                                }
1884
                            }
1885

    
1886
                            placeRunInputs.AddPoint(x, y);
1887

    
1888
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1889
                            {
1890
                                index += 0.01;
1891
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1892
                                    placeRunInputs.AddPoint(x, -0.1 - index);
1893
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1894
                                    placeRunInputs.AddPoint(-0.1 - index, y);
1895
                                else
1896
                                {
1897
                                    Line nextLine = groupLine.CONNECTORS[1].ConnectedObject as Line;
1898
                                    if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45)
1899
                                        placeRunInputs.AddPoint(-0.1 - index, y);
1900
                                    else
1901
                                        placeRunInputs.AddPoint(x, -0.1 - index);
1902
                                }
1903
                            }
1904
                        }
1905
                    }
1906
                }
1907

    
1908
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1909
                if (_lMConnector != null)
1910
                {
1911
                    _lMConnector.Commit();
1912
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1913

    
1914
                    bool bRemodelingStart = false;
1915
                    if (_LMSymbolStart != null)
1916
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1917
                    bool bRemodelingEnd = false;
1918
                    if (_LMSymbolEnd != null)
1919
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1920

    
1921
                    if (bRemodelingStart || bRemodelingEnd)
1922
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1923

    
1924
                    FlowMarkModeling(groupLine);
1925
                    LineNumberModelingOnlyOne(groupLine);
1926

    
1927
                    ReleaseCOMObjects(_lMConnector);
1928
                }
1929
                else if (!isBranchModeling)
1930
                {
1931
                    Log.Write("Main Line Modeling : " + groupLine.UID);
1932
                }
1933

    
1934
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1935
                x.ConnectedObject != null &&
1936
                x.ConnectedObject.GetType() == typeof(Line) &&
1937
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1938
                .Select(x => x.ConnectedObject)
1939
                .ToList();
1940

    
1941
                foreach (var item in removeLines)
1942
                    RemoveLineForModeling(item as Line);
1943

    
1944
                if (_LMAItem != null)
1945
                    ReleaseCOMObjects(_LMAItem);
1946
                if (placeRunInputs != null)
1947
                    ReleaseCOMObjects(placeRunInputs);
1948
                if (_LMSymbolStart != null)
1949
                    ReleaseCOMObjects(_LMSymbolStart);
1950
                if (_LMSymbolEnd != null)
1951
                    ReleaseCOMObjects(_LMSymbolEnd);
1952

    
1953
                if (isBranchModeling && BranchLines.Contains(groupLine))
1954
                    BranchLines.Remove(groupLine);
1955
            }
1956
        }
1957

    
1958
        private void RemoveLineForModeling(Line line)
1959
        {
1960
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1961
            if (modelItem != null)
1962
            {
1963
                foreach (LMRepresentation rep in modelItem.Representations)
1964
                {
1965
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1966
                    {
1967
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1968
                        dynamic OID = rep.get_GraphicOID().ToString();
1969
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1970
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1971
                        int verticesCount = lineStringGeometry.VertexCount;
1972
                        double[] vertices = null;
1973
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1974
                        for (int i = 0; i < verticesCount; i++)
1975
                        {
1976
                            double x = 0;
1977
                            double y = 0;
1978
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1979
                            if (verticesCount == 2 && (x < 0 || y < 0))
1980
                                _placement.PIDRemovePlacement(rep);
1981
                        }
1982
                        ReleaseCOMObjects(_LMConnector);
1983
                    }
1984
                }
1985

    
1986
                ReleaseCOMObjects(modelItem);
1987
            }
1988
        }
1989

    
1990
        private void GetConnectedLineGroup(Line line, List<Line> group)
1991
        {
1992
            if (!group.Contains(line))
1993
                group.Add(line);
1994
            foreach (var connector in line.CONNECTORS)
1995
            {
1996
                if (connector.ConnectedObject != null &&
1997
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1998
                    !group.Contains(connector.ConnectedObject) &&
1999
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
2000
                {
2001
                    Line connLine = connector.ConnectedObject as Line;
2002
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
2003
                    {
2004
                        if (line.CONNECTORS.IndexOf(connector) == 0)
2005
                            group.Insert(0, connLine);
2006
                        else
2007
                            group.Add(connLine);
2008
                        GetConnectedLineGroup(connLine, group);
2009
                    }
2010
                }
2011
            }
2012
        }
2013

    
2014
        private void LineCoordinateCorrection(List<Line> group)
2015
        {
2016
            // 순서대로 전 Item 기준 정렬
2017
            LineCoordinateCorrectionByStart(group);
2018

    
2019
            // 역으로 심볼이 있을 경우 좌표 보정
2020
            LineCoordinateCorrectionForLastLine(group);
2021
        }
2022

    
2023
        private void LineCoordinateCorrectionByStart(List<Line> group)
2024
        {
2025
            for (int i = 0; i < group.Count; i++)
2026
            {
2027
                Line line = group[i];
2028
                if (i == 0)
2029
                {
2030
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
2031
                    if (symbolConnector != null)
2032
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
2033
                }
2034
                else if (i != 0)
2035
                {
2036
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
2037
                }
2038
            }
2039
        }
2040

    
2041
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
2042
        {
2043
            Line checkLine = group[group.Count - 1];
2044
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
2045
            if (lastSymbolConnector != null)
2046
            {
2047
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
2048
                for (int i = group.Count - 2; i >= 0; i--)
2049
                {
2050
                    Line line = group[i + 1];
2051
                    Line prevLine = group[i];
2052

    
2053
                    // 같으면 보정
2054
                    if (line.SlopeType == prevLine.SlopeType)
2055
                        LineCoordinateCorrectionByConnItem(prevLine, line);
2056
                    else
2057
                    {
2058
                        if (line.SlopeType == SlopeType.HORIZONTAL)
2059
                        {
2060
                            double prevX = 0;
2061
                            double prevY = 0;
2062
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
2063
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
2064

    
2065
                            double x = 0;
2066
                            double y = 0;
2067
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
2068
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
2069
                        }
2070
                        else if (line.SlopeType == SlopeType.VERTICAL)
2071
                        {
2072
                            double prevX = 0;
2073
                            double prevY = 0;
2074
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
2075
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
2076

    
2077
                            double x = 0;
2078
                            double y = 0;
2079
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
2080
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
2081
                        }
2082
                        break;
2083
                    }
2084
                }
2085
            }
2086
        }
2087

    
2088
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
2089
        {
2090
            double x = 0;
2091
            double y = 0;
2092
            if (connItem.GetType() == typeof(Symbol))
2093
            {
2094
                Symbol targetSymbol = connItem as Symbol;
2095
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
2096
                if (targetConnector != null)
2097
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
2098
                else
2099
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
2100
            }
2101
            else if (connItem.GetType() == typeof(Line))
2102
            {
2103
                Line targetLine = connItem as Line;
2104
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
2105
            }
2106

    
2107
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
2108
        }
2109

    
2110
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
2111
        {
2112
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2113
            int index = line.CONNECTORS.IndexOf(connector);
2114
            if (index == 0)
2115
            {
2116
                line.SPPID.START_X = x;
2117
                line.SPPID.START_Y = y;
2118
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2119
                    line.SPPID.END_Y = y;
2120
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2121
                    line.SPPID.END_X = x;
2122
            }
2123
            else
2124
            {
2125
                line.SPPID.END_X = x;
2126
                line.SPPID.END_Y = y;
2127
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2128
                    line.SPPID.START_Y = y;
2129
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2130
                    line.SPPID.START_X = x;
2131
            }
2132
        }
2133

    
2134
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
2135
        {
2136
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2137
            int index = line.CONNECTORS.IndexOf(connector);
2138
            if (index == 0)
2139
            {
2140
                line.SPPID.START_X = x;
2141
                if (line.SlopeType == SlopeType.VERTICAL)
2142
                    line.SPPID.END_X = x;
2143
            }
2144
            else
2145
            {
2146
                line.SPPID.END_X = x;
2147
                if (line.SlopeType == SlopeType.VERTICAL)
2148
                    line.SPPID.START_X = x;
2149
            }
2150
        }
2151

    
2152
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
2153
        {
2154
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2155
            int index = line.CONNECTORS.IndexOf(connector);
2156
            if (index == 0)
2157
            {
2158
                line.SPPID.START_Y = y;
2159
                if (line.SlopeType == SlopeType.HORIZONTAL)
2160
                    line.SPPID.END_Y = y;
2161
            }
2162
            else
2163
            {
2164
                line.SPPID.END_Y = y;
2165
                if (line.SlopeType == SlopeType.HORIZONTAL)
2166
                    line.SPPID.START_Y = y;
2167
            }
2168
        }
2169

    
2170
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
2171
        {
2172
            if (symbol != null)
2173
            {
2174
                string repID = symbol.AsLMRepresentation().Id;
2175
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
2176
                string lineUID = line.UID;
2177

    
2178
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
2179
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
2180
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
2181

    
2182
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
2183
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
2184
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
2185

    
2186
                if (startSpecBreak != null || startEndBreak != null)
2187
                    result = true;
2188
            }
2189
        }
2190

    
2191
        /// <summary>
2192
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
2193
        /// </summary>
2194
        /// <param name="lines"></param>
2195
        /// <param name="prevLMConnector"></param>
2196
        /// <param name="startSymbol"></param>
2197
        /// <param name="endSymbol"></param>
2198
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
2199
        {
2200
            string symbolPath = string.Empty;
2201
            #region get symbol path
2202
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
2203
            symbolPath = GetSPPIDFileName(modelItem);
2204
            ReleaseCOMObjects(modelItem);
2205
            #endregion
2206
            bool diagonal = false;
2207
            if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL)
2208
                diagonal = true;
2209
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2210
            LMConnector newConnector = null;
2211
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
2212
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2213
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2214
            int verticesCount = lineStringGeometry.VertexCount;
2215
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2216

    
2217
            List<double[]> vertices = new List<double[]>();
2218
            for (int i = 1; i <= verticesCount; i++)
2219
            {
2220
                double x = 0;
2221
                double y = 0;
2222
                lineStringGeometry.GetVertex(i, ref x, ref y);
2223
                vertices.Add(new double[] { x, y });
2224
            }
2225

    
2226
            for (int i = 0; i < vertices.Count; i++)
2227
            {
2228
                double[] points = vertices[i];
2229
                // 시작 심볼이 있고 첫번째 좌표일 때
2230
                if (startSymbol != null && i == 0)
2231
                {
2232
                    if (bStart)
2233
                    {
2234
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
2235
                        if (slopeType == SlopeType.HORIZONTAL)
2236
                            placeRunInputs.AddPoint(points[0], -0.1);
2237
                        else if (slopeType == SlopeType.VERTICAL)
2238
                            placeRunInputs.AddPoint(-0.1, points[1]);
2239
                        else
2240
                            placeRunInputs.AddPoint(points[0], -0.1);
2241

    
2242
                        placeRunInputs.AddPoint(points[0], points[1]);
2243
                    }
2244
                    else
2245
                    {
2246
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal);
2247
                    }
2248
                }
2249
                // 마지막 심볼이 있고 마지막 좌표일 때
2250
                else if (endSymbol != null && i == vertices.Count - 1)
2251
                {
2252
                    if (bEnd)
2253
                    {
2254
                        placeRunInputs.AddPoint(points[0], points[1]);
2255

    
2256
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
2257
                        if (slopeType == SlopeType.HORIZONTAL)
2258
                            placeRunInputs.AddPoint(points[0], -0.1);
2259
                        else if (slopeType == SlopeType.VERTICAL)
2260
                            placeRunInputs.AddPoint(-0.1, points[1]);
2261
                        else
2262
                            placeRunInputs.AddPoint(points[0], -0.1);
2263
                    }
2264
                    else
2265
                    {
2266
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal);
2267
                    }
2268
                }
2269
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
2270
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
2271
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal);
2272
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
2273
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
2274
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal);
2275
                else
2276
                    placeRunInputs.AddPoint(points[0], points[1]);
2277
            }
2278

    
2279
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
2280
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2281

    
2282
            ReleaseCOMObjects(placeRunInputs);
2283
            ReleaseCOMObjects(_LMAItem);
2284
            ReleaseCOMObjects(modelItem);
2285

    
2286
            if (newConnector != null)
2287
            {
2288
                newConnector.Commit();
2289
                if (startSymbol != null && bStart)
2290
                {
2291
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2292
                    placeRunInputs = new PlaceRunInputs();
2293
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
2294
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
2295
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2296
                    if (_LMConnector != null)
2297
                    {
2298
                        _LMConnector.Commit();
2299
                        RemoveConnectorForReModelingLine(newConnector);
2300
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
2301
                        ReleaseCOMObjects(_LMConnector);
2302
                    }
2303
                    ReleaseCOMObjects(placeRunInputs);
2304
                    ReleaseCOMObjects(_LMAItem);
2305
                }
2306

    
2307
                if (endSymbol != null && bEnd)
2308
                {
2309
                    if (startSymbol != null)
2310
                    {
2311
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
2312
                        newConnector = dicVertices.First().Key;
2313
                    }
2314

    
2315
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2316
                    placeRunInputs = new PlaceRunInputs();
2317
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2318
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2319
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2320
                    if (_LMConnector != null)
2321
                    {
2322
                        _LMConnector.Commit();
2323
                        RemoveConnectorForReModelingLine(newConnector);
2324
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
2325
                        ReleaseCOMObjects(_LMConnector);
2326
                    }
2327
                    ReleaseCOMObjects(placeRunInputs);
2328
                    ReleaseCOMObjects(_LMAItem);
2329
                }
2330

    
2331
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2332
                ReleaseCOMObjects(newConnector);
2333
            }
2334

    
2335
            ReleaseCOMObjects(modelItem);
2336
        }
2337

    
2338
        /// <summary>
2339
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
2340
        /// </summary>
2341
        /// <param name="connector"></param>
2342
        private void RemoveConnectorForReModelingLine(LMConnector connector)
2343
        {
2344
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
2345
            foreach (var item in dicVertices)
2346
            {
2347
                if (item.Value.Count == 2)
2348
                {
2349
                    bool result = false;
2350
                    foreach (var point in item.Value)
2351
                    {
2352
                        if (point[0] < 0 || point[1] < 0)
2353
                        {
2354
                            result = true;
2355
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2356
                            break;
2357
                        }
2358
                    }
2359

    
2360
                    if (result)
2361
                        break;
2362
                }
2363
            }
2364
            foreach (var item in dicVertices)
2365
                ReleaseCOMObjects(item.Key);
2366
        }
2367

    
2368
        /// <summary>
2369
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2370
        /// </summary>
2371
        /// <param name="symbol"></param>
2372
        /// <param name="line"></param>
2373
        /// <returns></returns>
2374
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2375
        {
2376
            LMSymbol _LMSymbol = null;
2377
            foreach (var connector in symbol.CONNECTORS)
2378
            {
2379
                if (connector.CONNECTEDITEM == line.UID)
2380
                {
2381
                    if (connector.Index == 0)
2382
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2383
                    else
2384
                    {
2385
                        ChildSymbol child = null;
2386
                        foreach (var childSymbol in symbol.ChildSymbols)
2387
                        {
2388
                            if (childSymbol.Connectors.Contains(connector))
2389
                                child = childSymbol;
2390
                            else
2391
                                child = GetChildSymbolByConnector(childSymbol, connector);
2392

    
2393
                            if (child != null)
2394
                                break;
2395
                        }
2396

    
2397
                        if (child != null)
2398
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2399
                    }
2400

    
2401
                    break;
2402
                }
2403
            }
2404

    
2405
            return _LMSymbol;
2406
        }
2407

    
2408
        /// <summary>
2409
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2410
        /// </summary>
2411
        /// <param name="item"></param>
2412
        /// <param name="connector"></param>
2413
        /// <returns></returns>
2414
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2415
        {
2416
            foreach (var childSymbol in item.ChildSymbols)
2417
            {
2418
                if (childSymbol.Connectors.Contains(connector))
2419
                    return childSymbol;
2420
                else
2421
                    return GetChildSymbolByConnector(childSymbol, connector);
2422
            }
2423

    
2424
            return null;
2425
        }
2426

    
2427
        /// <summary>
2428
        /// EndBreak 모델링 메서드
2429
        /// </summary>
2430
        /// <param name="endBreak"></param>
2431
        private void EndBreakModeling(EndBreak endBreak)
2432
        {
2433
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2434
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2435

    
2436
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2437
            if (ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Symbol) && targetLMConnector != null)
2438
                targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector);
2439

    
2440
            if (targetLMConnector != null)
2441
            {
2442
                double[] point = GetSegmentPoint(ownerObj, connectedItem, targetLMConnector);
2443
                Array array = null;
2444
                if (point != null)
2445
                    array = new double[] { 0, point[0], point[1] };
2446
                else
2447
                    array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2448
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2449
                if (_LmLabelPersist != null)
2450
                {
2451
                    _LmLabelPersist.Commit();
2452
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2453
                    if (_LmLabelPersist.ModelItemObject != null)
2454
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2455
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2456
                    ReleaseCOMObjects(_LmLabelPersist);
2457
                }
2458
                ReleaseCOMObjects(targetLMConnector);
2459
            }
2460
            else
2461
            {
2462
                Log.Write("End Break UID : " + endBreak.UID);
2463
                Log.Write("Can't find targetLMConnector");
2464
            }
2465
        }
2466

    
2467
        private LMConnector ReModelingZeroLengthLMConnectorForSegment(LMConnector connector, string changeSymbolPath = null)
2468
        {
2469
            string symbolPath = string.Empty;
2470
            #region get symbol path
2471
            if (string.IsNullOrEmpty(changeSymbolPath))
2472
            {
2473
                LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2474
                symbolPath = GetSPPIDFileName(modelItem);
2475
                ReleaseCOMObjects(modelItem);
2476
            }
2477
            else
2478
                symbolPath = changeSymbolPath;
2479
            
2480
            #endregion
2481

    
2482
            LMConnector newConnector = null;
2483
            dynamic OID = connector.get_GraphicOID().ToString();
2484
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2485
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2486
            int verticesCount = lineStringGeometry.VertexCount;
2487
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2488
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2489

    
2490
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2491
            {
2492
                double[] vertices = null;
2493
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2494
                double x = 0;
2495
                double y = 0;
2496
                lineStringGeometry.GetVertex(1, ref x, ref y);
2497

    
2498
                string flowDirection = string.Empty;
2499
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2500
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2501
                    flowDirection = flowAttribute.get_Value().ToString();
2502

    
2503
                if (flowDirection == "End 1 is downstream (Outlet)")
2504
                {
2505
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2506
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2507
                    flowDirection = "End 1 is upstream (Inlet)";
2508
                }
2509
                else
2510
                {
2511
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2512
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2513
                }
2514
                string oldModelItemId = connector.ModelItemID;
2515
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2516
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2517
                newConnector.Commit();
2518
                ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID);
2519
                if (!string.IsNullOrEmpty(flowDirection))
2520
                    newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection);
2521
                ReleaseCOMObjects(connector);
2522

    
2523
                foreach (var line in document.LINES.FindAll(z => z.SPPID.ModelItemId == oldModelItemId))
2524
                {
2525
                    foreach (var repId in line.SPPID.Representations)
2526
                    {
2527
                        LMConnector _connector = dataSource.GetConnector(repId);
2528
                        if (_connector != null && _connector.get_ItemStatus() == "Active")
2529
                        {
2530
                            if (line.SPPID.ModelItemId != _connector.ModelItemID)
2531
                            {
2532
                                line.SPPID.ModelItemId = _connector.ModelItemID;
2533
                                line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId);
2534
                            }
2535
                        }
2536
                        ReleaseCOMObjects(_connector);
2537
                        _connector = null;
2538
                    }
2539
                }
2540
            }
2541

    
2542
            return newConnector;
2543
        }
2544

    
2545
        /// <summary>
2546
        /// SpecBreak Modeling 메서드
2547
        /// </summary>
2548
        /// <param name="specBreak"></param>
2549
        private void SpecBreakModeling(SpecBreak specBreak)
2550
        {
2551
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2552
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2553

    
2554
            if (upStreamObj != null &&
2555
                downStreamObj != null)
2556
            {
2557
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2558
                if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Symbol) && targetLMConnector != null)
2559
                    targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector);
2560

    
2561
                if (targetLMConnector != null)
2562
                {
2563
                    foreach (var attribute in specBreak.ATTRIBUTES)
2564
                    {
2565
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2566
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2567
                        {
2568
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2569
                            double[] point = GetSegmentPoint(upStreamObj, downStreamObj, targetLMConnector);
2570
                            Array array = null;
2571
                            if (point != null)
2572
                                array = new double[] { 0, point[0], point[1] };
2573
                            else
2574
                                array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2575
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2576

    
2577
                            if (_LmLabelPersist != null)
2578
                            {
2579
                                _LmLabelPersist.Commit();
2580
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2581
                                if (_LmLabelPersist.ModelItemObject != null)
2582
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2583
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2584
                                ReleaseCOMObjects(_LmLabelPersist);
2585
                            }
2586
                        }
2587
                    }
2588
                    ReleaseCOMObjects(targetLMConnector);
2589
                }
2590
                else
2591
                {
2592
                    Log.Write("Spec Break UID : " + specBreak.UID);
2593
                    Log.Write("Can't find targetLMConnector");
2594
                }
2595
            }
2596
        }
2597

    
2598
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2599
        {
2600
            LMConnector targetConnector = null;
2601
            Symbol targetSymbol = targetObj as Symbol;
2602
            Symbol connectedSymbol = connectedObj as Symbol;
2603
            Line targetLine = targetObj as Line;
2604
            Line connectedLine = connectedObj as Line;
2605
            if (targetSymbol != null && connectedSymbol != null)
2606
            {
2607
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2608
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2609

    
2610
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2611
                {
2612
                    if (connector.get_ItemStatus() != "Active")
2613
                        continue;
2614

    
2615
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2616
                    {
2617
                        targetConnector = connector;
2618
                        break;
2619
                    }
2620
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2621
                    {
2622
                        targetConnector = connector;
2623
                        break;
2624
                    }
2625
                }
2626

    
2627
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2628
                {
2629
                    if (connector.get_ItemStatus() != "Active")
2630
                        continue;
2631

    
2632
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2633
                    {
2634
                        targetConnector = connector;
2635
                        break;
2636
                    }
2637
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2638
                    {
2639
                        targetConnector = connector;
2640
                        break;
2641
                    }
2642
                }
2643

    
2644
                ReleaseCOMObjects(targetLMSymbol);
2645
                ReleaseCOMObjects(connectedLMSymbol);
2646
            }
2647
            else if (targetLine != null && connectedLine != null)
2648
            {
2649
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2650
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2651

    
2652
                if (targetModelItem != null && targetModelItem.get_ItemStatus() == "Active" && connectedModelItem != null && connectedModelItem.get_ItemStatus() == "Active")
2653
                {
2654
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2655
                    {
2656
                        if (targetConnector != null)
2657
                            break;
2658

    
2659
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2660
                        {
2661
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2662

    
2663
                            if (IsConnected(_LMConnector, connectedModelItem))
2664
                                targetConnector = _LMConnector;
2665
                            else
2666
                                ReleaseCOMObjects(_LMConnector);
2667
                        }
2668
                    }
2669

    
2670
                    ReleaseCOMObjects(targetModelItem);
2671
                }
2672
            }
2673
            else
2674
            {
2675
                LMSymbol connectedLMSymbol = null;
2676
                if (connectedSymbol != null)
2677
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2678
                else if (targetSymbol != null)
2679
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2680
                else
2681
                {
2682

    
2683
                }
2684
                LMModelItem targetModelItem = null;
2685
                if (targetLine != null)
2686
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2687
                else if (connectedLine != null)
2688
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2689
                else
2690
                {
2691

    
2692
                }
2693
                if (connectedLMSymbol != null && targetModelItem != null)
2694
                {
2695
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2696
                    {
2697
                        if (connector.get_ItemStatus() != "Active")
2698
                            continue;
2699

    
2700
                        if (IsConnected(connector, targetModelItem))
2701
                        {
2702
                            targetConnector = connector;
2703
                            break;
2704
                        }
2705
                    }
2706

    
2707
                    if (targetConnector == null)
2708
                    {
2709
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2710
                        {
2711
                            if (connector.get_ItemStatus() != "Active")
2712
                                continue;
2713

    
2714
                            if (IsConnected(connector, targetModelItem))
2715
                            {
2716
                                targetConnector = connector;
2717
                                break;
2718
                            }
2719
                        }
2720
                    }
2721
                }
2722

    
2723
            }
2724

    
2725
            return targetConnector;
2726
        }
2727

    
2728
        private double[] GetSegmentPoint(object targetObj, object connObj, LMConnector targetConnector)
2729
        {
2730
            double[] result = null;
2731
            Line targetLine = targetObj as Line;
2732
            Symbol targetSymbol = targetObj as Symbol;
2733
            Line connLine = connObj as Line;
2734
            Symbol connSymbol = connObj as Symbol;
2735

    
2736
            double zeroLengthMove = GridSetting.GetInstance().Length * 3;
2737
            double lineMove = GridSetting.GetInstance().Length * 3;
2738
            if (Convert.ToBoolean(targetConnector.get_IsZeroLength()))
2739
            {
2740
                result = GetConnectorVertices(targetConnector)[0];
2741
                if (targetSymbol != null && connSymbol != null)
2742
                {
2743
                    SlopeType slopeType = SPPIDUtil.CalcSlope(targetSymbol.SPPID.SPPID_X, targetSymbol.SPPID.SPPID_Y, connSymbol.SPPID.SPPID_X, connSymbol.SPPID.SPPID_Y);
2744
                    if (slopeType == SlopeType.HORIZONTAL)
2745
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2746
                    else if (slopeType == SlopeType.VERTICAL)
2747
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
2748
                }
2749
                else if (targetLine != null)
2750
                {
2751
                    if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2752
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2753
                    else if (targetLine.SlopeType == SlopeType.VERTICAL)
2754
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
2755
                }
2756
                else if (connLine != null)
2757
                {
2758
                    if (connLine.SlopeType == SlopeType.HORIZONTAL)
2759
                        result = new double[] { result[0], result[1] - zeroLengthMove };
2760
                    else if (connLine.SlopeType == SlopeType.VERTICAL)
2761
                        result = new double[] { result[0] - zeroLengthMove, result[1] };
2762
                }
2763
            }
2764
            else
2765
            {
2766
                if (targetObj.GetType() == typeof(Line) && connObj.GetType() == typeof(Line))
2767
                {
2768
                    Line line = connObj as Line;
2769
                    LMConnector connectedConnector = null;
2770
                    int connIndex = 0;
2771
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2772
                    FindConnectedConnector(targetConnector, modelItem, ref connectedConnector, ref connIndex);
2773

    
2774
                    List<double[]> vertices = GetConnectorVertices(targetConnector);
2775

    
2776
                    ReleaseCOMObjects(modelItem);
2777
                    ReleaseCOMObjects(connectedConnector);
2778

    
2779
                    if (vertices.Count > 0)
2780
                    {
2781
                        if (connIndex == 1)
2782
                            result = vertices[0];
2783
                        else if (connIndex == 2)
2784
                            result = vertices[vertices.Count - 1];
2785

    
2786
                        if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2787
                        {
2788
                            result = new double[] { result[0], result[1] - lineMove };
2789
                            if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X)
2790
                            {
2791
                                result = new double[] { result[0] - lineMove, result[1] };
2792
                            }
2793
                            else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X)
2794
                            {
2795
                                result = new double[] { result[0] + lineMove, result[1] };
2796
                            }
2797
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X)
2798
                            {
2799
                                result = new double[] { result[0] + lineMove, result[1] };
2800
                            }
2801
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X)
2802
                            {
2803
                                result = new double[] { result[0] - lineMove, result[1] };
2804
                            }
2805
                        }
2806
                        else if (targetLine.SlopeType == SlopeType.VERTICAL)
2807
                        {
2808
                            result = new double[] { result[0] - lineMove, result[1] };
2809
                            if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y)
2810
                            {
2811
                                result = new double[] { result[0], result[1] - lineMove };
2812
                            }
2813
                            else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y)
2814
                            {
2815
                                result = new double[] { result[0], result[1] + lineMove };
2816
                            }
2817
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y)
2818
                            {
2819
                                result = new double[] { result[0], result[1] + lineMove };
2820
                            }
2821
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y)
2822
                            {
2823
                                result = new double[] { result[0], result[1] - lineMove };
2824
                            }
2825
                        }
2826
                            
2827
                    }
2828
                }
2829
                else
2830
                {
2831
                    Log.Write("error in GetSegemtPoint");
2832
                }
2833
            }
2834

    
2835
            return result;
2836
        }
2837

    
2838
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2839
        {
2840
            bool result = false;
2841

    
2842
            foreach (LMRepresentation rep in modelItem.Representations)
2843
            {
2844
                if (result)
2845
                    break;
2846

    
2847
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2848
                {
2849
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2850

    
2851
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2852
                        connector.ConnectItem1SymbolObject != null &&
2853
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2854
                    {
2855
                        result = true;
2856
                        ReleaseCOMObjects(_LMConnector);
2857
                        break;
2858
                    }
2859
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2860
                        connector.ConnectItem2SymbolObject != null &&
2861
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2862
                    {
2863
                        result = true;
2864
                        ReleaseCOMObjects(_LMConnector);
2865
                        break;
2866
                    }
2867
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2868
                        connector.ConnectItem1SymbolObject != null &&
2869
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2870
                    {
2871
                        result = true;
2872
                        ReleaseCOMObjects(_LMConnector);
2873
                        break;
2874
                    }
2875
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2876
                        connector.ConnectItem2SymbolObject != null &&
2877
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2878
                    {
2879
                        result = true;
2880
                        ReleaseCOMObjects(_LMConnector);
2881
                        break;
2882
                    }
2883

    
2884
                    ReleaseCOMObjects(_LMConnector);
2885
                }
2886
            }
2887

    
2888

    
2889
            return result;
2890
        }
2891

    
2892
        private void FindConnectedConnector(LMConnector connector, LMModelItem modelItem, ref LMConnector connectedConnector, ref int connectorIndex)
2893
        {
2894
            foreach (LMRepresentation rep in modelItem.Representations)
2895
            {
2896
                if (connectedConnector != null)
2897
                    break;
2898

    
2899
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2900
                {
2901
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2902

    
2903
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2904
                        connector.ConnectItem1SymbolObject != null &&
2905
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2906
                    {
2907
                        connectedConnector = _LMConnector;
2908
                        connectorIndex = 1;
2909
                        break;
2910
                    }
2911
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2912
                        connector.ConnectItem2SymbolObject != null &&
2913
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2914
                    {
2915
                        connectedConnector = _LMConnector;
2916
                        connectorIndex = 2;
2917
                        break;
2918
                    }
2919
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2920
                        connector.ConnectItem1SymbolObject != null &&
2921
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2922
                    {
2923
                        connectedConnector = _LMConnector;
2924
                        connectorIndex = 1;
2925
                        break;
2926
                    }
2927
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2928
                        connector.ConnectItem2SymbolObject != null &&
2929
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2930
                    {
2931
                        connectedConnector = _LMConnector;
2932
                        connectorIndex = 2;
2933
                        break;
2934
                    }
2935

    
2936
                    if (connectedConnector == null)
2937
                        ReleaseCOMObjects(_LMConnector);
2938
                }
2939
            }
2940
        }
2941

    
2942
        /// <summary>
2943
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2944
        /// </summary>
2945
        /// <param name="modelItemID1"></param>
2946
        /// <param name="modelItemID2"></param>
2947
        private void JoinRun(string modelId1, string modelId2, ref string survivorId)
2948
        {
2949
            try
2950
            {
2951
                LMModelItem modelItem1 = dataSource.GetModelItem(modelId1);
2952
                _LMAItem item1 = modelItem1.AsLMAItem();
2953
                LMModelItem modelItem2 = dataSource.GetModelItem(modelId2);
2954
                _LMAItem item2 = modelItem2.AsLMAItem();
2955

    
2956
                // item2가 item1으로 조인
2957
                _placement.PIDJoinRuns(ref item1, ref item2);
2958
                item1.Commit();
2959
                item2.Commit();
2960

    
2961
                string beforeID = string.Empty;
2962
                string afterID = string.Empty;
2963

    
2964
                if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
2965
                {
2966
                    beforeID = modelItem2.Id;
2967
                    afterID = modelItem1.Id;
2968
                    survivorId = afterID;
2969
                    LMAAttribute attribute = modelItem1.Attributes["FlowDirection"];
2970
                    if (attribute != null)
2971
                        attribute.set_Value("End 1 is upstream (Inlet)");
2972
                }
2973
                else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
2974
                {
2975
                    beforeID = modelItem1.Id;
2976
                    afterID = modelItem2.Id;
2977
                    survivorId = afterID;
2978
                    LMAAttribute attribute = modelItem2.Attributes["FlowDirection"];
2979
                    if (attribute != null)
2980
                        attribute.set_Value("End 1 is upstream (Inlet)");
2981
                }
2982
                else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active")
2983
                    survivorId = null;
2984
                else
2985
                {
2986
                    Log.Write("잘못된 경우");
2987
                    survivorId = null;
2988
                }
2989

    
2990
                if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID))
2991
                {
2992
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
2993
                    foreach (var line in lines)
2994
                        line.SPPID.ModelItemId = afterID;
2995
                }
2996

    
2997
                ReleaseCOMObjects(modelItem1);
2998
                ReleaseCOMObjects(item1);
2999
                ReleaseCOMObjects(modelItem2);
3000
                ReleaseCOMObjects(item2);
3001
            }
3002
            catch (Exception ex)
3003
            {
3004
                Log.Write("Join Error");
3005
                Log.Write(ex.Message);
3006
            }
3007
        }
3008

    
3009
        private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId)
3010
        {
3011
            List<string> temp = new List<string>();
3012
            List<LMConnector> connectors = new List<LMConnector>();
3013
            foreach (LMConnector connector in symbol.Avoid1Connectors)
3014
            {
3015
                if (connector.get_ItemStatus() != "Active")
3016
                    continue;
3017

    
3018
                LMModelItem modelItem = connector.ModelItemObject;
3019
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
3020
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
3021
                    temp.Add(modelItem.Id);
3022

    
3023
                if (temp.Contains(modelItem.Id) &&
3024
                    connOtherSymbol != null &&
3025
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
3026
                    Convert.ToBoolean(connector.get_IsZeroLength()))
3027
                    temp.Remove(modelItem.Id);
3028

    
3029

    
3030
                if (temp.Contains(modelItem.Id))
3031
                    connectors.Add(connector);
3032
                ReleaseCOMObjects(connOtherSymbol);
3033
                connOtherSymbol = null;
3034
                ReleaseCOMObjects(modelItem);
3035
                modelItem = null;
3036
            }
3037

    
3038
            foreach (LMConnector connector in symbol.Avoid2Connectors)
3039
            {
3040
                if (connector.get_ItemStatus() != "Active")
3041
                    continue;
3042

    
3043
                LMModelItem modelItem = connector.ModelItemObject;
3044
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
3045
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
3046
                    temp.Add(modelItem.Id);
3047

    
3048
                if (temp.Contains(modelItem.Id) &&
3049
                    connOtherSymbol != null &&
3050
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
3051
                    Convert.ToBoolean(connector.get_IsZeroLength()))
3052
                    temp.Remove(modelItem.Id);
3053

    
3054
                if (temp.Contains(modelItem.Id))
3055
                    connectors.Add(connector);
3056
                ReleaseCOMObjects(connOtherSymbol);
3057
                connOtherSymbol = null;
3058
                ReleaseCOMObjects(modelItem);
3059
                modelItem = null;
3060
            }
3061

    
3062

    
3063
            List<string> result = new List<string>();
3064
            string originalName = GetSPPIDFileName(modelId);
3065
            foreach (var connector in connectors)
3066
            {
3067
                string fileName = GetSPPIDFileName(connector.ModelItemID);
3068
                if (originalName == fileName)
3069
                    result.Add(connector.ModelItemID);
3070
                else
3071
                {
3072
                    if (document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID) == null && Convert.ToBoolean(connector.get_IsZeroLength()))
3073
                        result.Add(connector.ModelItemID);
3074
                    else
3075
                    {
3076
                        Line line1 = document.LINES.Find(x => x.SPPID.ModelItemId == modelId);
3077
                        Line line2 = document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID.ToString());
3078
                        if (line1 != null && line2 != null && line1.TYPE == line2.TYPE)
3079
                            result.Add(connector.ModelItemID);
3080
                    }
3081
                }
3082
            }
3083

    
3084
            foreach (var connector in connectors)
3085
                ReleaseCOMObjects(connector);
3086
            
3087
            return result;
3088

    
3089

    
3090
            LMSymbol FindOtherConnectedSymbol(LMConnector connector)
3091
            {
3092
                LMSymbol findResult = null;
3093
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.Id != symbol.Id && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
3094
                    findResult = connector.ConnectItem1SymbolObject;
3095
                else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.Id != symbol.Id && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
3096
                    findResult = connector.ConnectItem2SymbolObject;
3097

    
3098
                return findResult;
3099
            }
3100
        }
3101

    
3102
        /// <summary>
3103
        /// PipeRun의 좌표를 가져오는 메서드
3104
        /// </summary>
3105
        /// <param name="modelId"></param>
3106
        /// <returns></returns>
3107
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
3108
        {
3109
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
3110
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
3111

    
3112
            if (modelItem != null)
3113
            {
3114
                foreach (LMRepresentation rep in modelItem.Representations)
3115
                {
3116
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3117
                    {
3118
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
3119
                        connectorVertices.Add(_LMConnector, new List<double[]>());
3120
                        dynamic OID = rep.get_GraphicOID().ToString();
3121
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
3122
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
3123
                        int verticesCount = lineStringGeometry.VertexCount;
3124
                        double[] vertices = null;
3125
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
3126
                        for (int i = 0; i < verticesCount; i++)
3127
                        {
3128
                            double x = 0;
3129
                            double y = 0;
3130
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
3131
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
3132
                        }
3133
                    }
3134
                }
3135

    
3136
                ReleaseCOMObjects(modelItem);
3137
            }
3138

    
3139
            return connectorVertices;
3140
        }
3141

    
3142
        private List<double[]> GetConnectorVertices(LMConnector connector)
3143
        {
3144
            List<double[]> vertices = new List<double[]>();
3145
            if (connector != null)
3146
            {
3147
                dynamic OID = connector.get_GraphicOID().ToString();
3148
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
3149
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
3150
                int verticesCount = lineStringGeometry.VertexCount;
3151
                double[] value = null;
3152
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
3153
                for (int i = 0; i < verticesCount; i++)
3154
                {
3155
                    double x = 0;
3156
                    double y = 0;
3157
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
3158
                    vertices.Add(new double[] { x, y });
3159
                }
3160
            }
3161
            return vertices;
3162
        }
3163

    
3164
        /// <summary>
3165
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
3166
        /// </summary>
3167
        /// <param name="connectorVertices"></param>
3168
        /// <param name="connX"></param>
3169
        /// <param name="connY"></param>
3170
        /// <returns></returns>
3171
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
3172
        {
3173
            double length = double.MaxValue;
3174
            LMConnector targetConnector = null;
3175
            foreach (var item in connectorVertices)
3176
            {
3177
                List<double[]> points = item.Value;
3178
                for (int i = 0; i < points.Count - 1; i++)
3179
                {
3180
                    double[] point1 = points[i];
3181
                    double[] point2 = points[i + 1];
3182
                    double x1 = Math.Min(point1[0], point2[0]);
3183
                    double y1 = Math.Min(point1[1], point2[1]);
3184
                    double x2 = Math.Max(point1[0], point2[0]);
3185
                    double y2 = Math.Max(point1[1], point2[1]);
3186

    
3187
                    if ((x1 <= connX && x2 >= connX) ||
3188
                        (y1 <= connY && y2 >= connY))
3189
                    {
3190
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
3191
                        if (length >= distance)
3192
                        {
3193
                            targetConnector = item.Key;
3194
                            length = distance;
3195
                        }
3196

    
3197
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
3198
                        if (length >= distance)
3199
                        {
3200
                            targetConnector = item.Key;
3201
                            length = distance;
3202
                        }
3203
                    }
3204
                }
3205
            }
3206

    
3207
            // 못찾았을때.
3208
            length = double.MaxValue;
3209
            if (targetConnector == null)
3210
            {
3211
                foreach (var item in connectorVertices)
3212
                {
3213
                    List<double[]> points = item.Value;
3214

    
3215
                    foreach (double[] point in points)
3216
                    {
3217
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
3218
                        if (length >= distance)
3219
                        {
3220
                            targetConnector = item.Key;
3221
                            length = distance;
3222
                        }
3223
                    }
3224
                }
3225
            }
3226

    
3227
            return targetConnector;
3228
        }
3229

    
3230
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
3231
        {
3232
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
3233
            if (vertices.Count == 0)
3234
                return null;
3235

    
3236
            double length = double.MaxValue;
3237
            LMConnector targetConnector = null;
3238
            double[] resultPoint = null;
3239
            List<double[]> targetVertices = null;
3240

    
3241
            // Vertices 포인트에 제일 가까운곳
3242
            foreach (var item in vertices)
3243
            {
3244
                List<double[]> points = item.Value;
3245
                for (int i = 0; i < points.Count; i++)
3246
                {
3247
                    double[] point = points[i];
3248
                    double tempX = point[0];
3249
                    double tempY = point[1];
3250

    
3251
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
3252
                    if (length >= distance)
3253
                    {
3254
                        targetConnector = item.Key;
3255
                        length = distance;
3256
                        resultPoint = point;
3257
                        targetVertices = item.Value;
3258
                    }
3259
                }
3260
            }
3261

    
3262
            // Vertices Cross에 제일 가까운곳
3263
            foreach (var item in vertices)
3264
            {
3265
                List<double[]> points = item.Value;
3266
                for (int i = 0; i < points.Count - 1; i++)
3267
                {
3268
                    double[] point1 = points[i];
3269
                    double[] point2 = points[i + 1];
3270

    
3271
                    double maxLineX = Math.Max(point1[0], point2[0]);
3272
                    double minLineX = Math.Min(point1[0], point2[0]);
3273
                    double maxLineY = Math.Max(point1[1], point2[1]);
3274
                    double minLineY = Math.Min(point1[1], point2[1]);
3275

    
3276
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
3277

    
3278
                    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]);
3279
                    if (crossingPoint != null)
3280
                    {
3281
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
3282
                        if (length >= distance)
3283
                        {
3284
                            if (slope == SlopeType.Slope &&
3285
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
3286
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
3287
                            {
3288
                                targetConnector = item.Key;
3289
                                length = distance;
3290
                                resultPoint = crossingPoint;
3291
                                targetVertices = item.Value;
3292
                            }
3293
                            else if (slope == SlopeType.HORIZONTAL &&
3294
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
3295
                            {
3296
                                targetConnector = item.Key;
3297
                                length = distance;
3298
                                resultPoint = crossingPoint;
3299
                                targetVertices = item.Value;
3300
                            }
3301
                            else if (slope == SlopeType.VERTICAL &&
3302
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
3303
                            {
3304
                                targetConnector = item.Key;
3305
                                length = distance;
3306
                                resultPoint = crossingPoint;
3307
                                targetVertices = item.Value;
3308
                            }
3309
                        }
3310
                    }
3311
                }
3312
            }
3313

    
3314
            foreach (var item in vertices)
3315
                if (item.Key != null && item.Key != targetConnector)
3316
                    ReleaseCOMObjects(item.Key);
3317

    
3318
            if (SPPIDUtil.IsBranchLine(line, targetLine))
3319
            {
3320
                double tempResultX = resultPoint[0];
3321
                double tempResultY = resultPoint[1];
3322
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
3323

    
3324
                GridSetting gridSetting = GridSetting.GetInstance();
3325

    
3326
                for (int i = 0; i < targetVertices.Count; i++)
3327
                {
3328
                    double[] point = targetVertices[i];
3329
                    double tempX = targetVertices[i][0];
3330
                    double tempY = targetVertices[i][1];
3331
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
3332
                    if (tempX == tempResultX && tempY == tempResultY)
3333
                    {
3334
                        if (i == 0)
3335
                        {
3336
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
3337
                            bool containZeroLength = false;
3338
                            if (connSymbol != null)
3339
                            {
3340
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
3341
                                {
3342
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3343
                                        containZeroLength = true;
3344
                                }
3345
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
3346
                                {
3347
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3348
                                        containZeroLength = true;
3349
                                }
3350
                            }
3351

    
3352
                            if (connSymbol == null ||
3353
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
3354
                                containZeroLength)
3355
                            {
3356
                                bool bCalcX = false;
3357
                                bool bCalcY = false;
3358
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3359
                                    bCalcX = true;
3360
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
3361
                                    bCalcY = true;
3362
                                else
3363
                                {
3364
                                    bCalcX = true;
3365
                                    bCalcY = true;
3366
                                }
3367

    
3368
                                if (bCalcX)
3369
                                {
3370
                                    double nextX = targetVertices[i + 1][0];
3371
                                    double newX = 0;
3372
                                    if (nextX > tempX)
3373
                                    {
3374
                                        newX = tempX + gridSetting.Length;
3375
                                        if (newX > nextX)
3376
                                            newX = (point[0] + nextX) / 2;
3377
                                    }
3378
                                    else
3379
                                    {
3380
                                        newX = tempX - gridSetting.Length;
3381
                                        if (newX < nextX)
3382
                                            newX = (point[0] + nextX) / 2;
3383
                                    }
3384
                                    resultPoint = new double[] { newX, resultPoint[1] };
3385
                                }
3386

    
3387
                                if (bCalcY)
3388
                                {
3389
                                    double nextY = targetVertices[i + 1][1];
3390
                                    double newY = 0;
3391
                                    if (nextY > tempY)
3392
                                    {
3393
                                        newY = tempY + gridSetting.Length;
3394
                                        if (newY > nextY)
3395
                                            newY = (point[1] + nextY) / 2;
3396
                                    }
3397
                                    else
3398
                                    {
3399
                                        newY = tempY - gridSetting.Length;
3400
                                        if (newY < nextY)
3401
                                            newY = (point[1] + nextY) / 2;
3402
                                    }
3403
                                    resultPoint = new double[] { resultPoint[0], newY };
3404
                                }
3405
                            }
3406
                        }
3407
                        else if (i == targetVertices.Count - 1)
3408
                        {
3409
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
3410
                            bool containZeroLength = false;
3411
                            if (connSymbol != null)
3412
                            {
3413
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
3414
                                {
3415
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3416
                                        containZeroLength = true;
3417
                                }
3418
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
3419
                                {
3420
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3421
                                        containZeroLength = true;
3422
                                }
3423
                            }
3424

    
3425
                            if (connSymbol == null ||
3426
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
3427
                                containZeroLength)
3428
                            {
3429
                                bool bCalcX = false;
3430
                                bool bCalcY = false;
3431
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3432
                                    bCalcX = true;
3433
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
3434
                                    bCalcY = true;
3435
                                else
3436
                                {
3437
                                    bCalcX = true;
3438
                                    bCalcY = true;
3439
                                }
3440

    
3441
                                if (bCalcX)
3442
                                {
3443
                                    double nextX = targetVertices[i - 1][0];
3444
                                    double newX = 0;
3445
                                    if (nextX > tempX)
3446
                                    {
3447
                                        newX = tempX + gridSetting.Length;
3448
                                        if (newX > nextX)
3449
                                            newX = (point[0] + nextX) / 2;
3450
                                    }
3451
                                    else
3452
                                    {
3453
                                        newX = tempX - gridSetting.Length;
3454
                                        if (newX < nextX)
3455
                                            newX = (point[0] + nextX) / 2;
3456
                                    }
3457
                                    resultPoint = new double[] { newX, resultPoint[1] };
3458
                                }
3459

    
3460
                                if (bCalcY)
3461
                                {
3462
                                    double nextY = targetVertices[i - 1][1];
3463
                                    double newY = 0;
3464
                                    if (nextY > tempY)
3465
                                    {
3466
                                        newY = tempY + gridSetting.Length;
3467
                                        if (newY > nextY)
3468
                                            newY = (point[1] + nextY) / 2;
3469
                                    }
3470
                                    else
3471
                                    {
3472
                                        newY = tempY - gridSetting.Length;
3473
                                        if (newY < nextY)
3474
                                            newY = (point[1] + nextY) / 2;
3475
                                    }
3476
                                    resultPoint = new double[] { resultPoint[0], newY };
3477
                                }
3478
                            }
3479
                        }
3480
                        break;
3481
                    }
3482
                }
3483
            }
3484

    
3485
            x = resultPoint[0];
3486
            y = resultPoint[1];
3487

    
3488
            return targetConnector;
3489
        }
3490

    
3491
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
3492
        {
3493
            LMConnector result = null;
3494
            List<LMConnector> connectors = new List<LMConnector>();
3495
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3496

    
3497
            if (modelItem != null)
3498
            {
3499
                foreach (LMRepresentation rep in modelItem.Representations)
3500
                {
3501
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3502
                        connectors.Add(dataSource.GetConnector(rep.Id));
3503
                }
3504

    
3505
                ReleaseCOMObjects(modelItem);
3506
            }
3507

    
3508
            if (connectors.Count == 1)
3509
                result = connectors[0];
3510
            else
3511
                foreach (var item in connectors)
3512
                    ReleaseCOMObjects(item);
3513

    
3514
            return result;
3515
        }
3516

    
3517
        public List<string> GetRepresentations(string modelItemID)
3518
        {
3519
            List<string> result = new List<string>(); ;
3520
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3521
            if (modelItem != null)
3522
            {
3523
                foreach (LMRepresentation rep in modelItem.Representations)
3524
                {
3525
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3526
                        result.Add(rep.Id);
3527
                }
3528
                ReleaseCOMObjects(modelItem);
3529
            }
3530

    
3531
            return result;
3532
        }
3533

    
3534
        /// <summary>
3535
        /// Line Number Symbol을 실제로 Modeling하는 메서드
3536
        /// </summary>
3537
        /// <param name="lineNumber"></param>
3538
        private void LineNumberModelingOnlyOne(Line line)
3539
        {
3540
            LineNumber lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == line.UID);
3541
            if (lineNumber != null)
3542
            {
3543
                LMConnector connectedLMConnector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
3544
                if (connectedLMConnector != null)
3545
                {
3546
                    double x = 0;
3547
                    double y = 0;
3548
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3549

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

    
3553
                    if (_LmLabelPresist != null)
3554
                    {
3555
                        _LmLabelPresist.Commit();
3556
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3557
                        ReleaseCOMObjects(_LmLabelPresist);
3558
                    }
3559
                }
3560
            }
3561
        }
3562

    
3563
        private void LineNumberModeling(LineNumber lineNumber)
3564
        {
3565
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
3566
            if (line != null)
3567
            {
3568
                double x = 0;
3569
                double y = 0;
3570
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3571

    
3572
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3573
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y);
3574
                if (connectedLMConnector != null)
3575
                {
3576
                    Array points = new double[] { 0, x, y };
3577
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3578

    
3579
                    if (_LmLabelPresist != null)
3580
                    {
3581
                        _LmLabelPresist.Commit();
3582
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3583
                        ReleaseCOMObjects(_LmLabelPresist);
3584
                    }
3585
                }
3586

    
3587
                foreach (var item in connectorVertices)
3588
                    ReleaseCOMObjects(item.Key);
3589
            }
3590
        }
3591
        /// <summary>
3592
        /// Flow Mark Modeling
3593
        /// </summary>
3594
        /// <param name="line"></param>
3595
        private void FlowMarkModeling(Line line)
3596
        {
3597
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
3598
            {
3599
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
3600
                if (connector != null)
3601
                {
3602
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
3603
                    List<double[]> vertices = GetConnectorVertices(connector);
3604
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
3605
                    double[] point = vertices[vertices.Count - 1];
3606
                    Array array = new double[] { 0, point[0], point[1] };
3607
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
3608
                    if (_LMLabelPersist != null)
3609
                    {
3610
                        _LMLabelPersist.Commit();
3611
                        ReleaseCOMObjects(_LMLabelPersist);
3612
                    }
3613
                        
3614
                }
3615
            }
3616
        }
3617

    
3618
        /// <summary>
3619
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
3620
        /// </summary>
3621
        /// <param name="lineNumber"></param>
3622
        private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine)
3623
        {
3624
            foreach (LineRun run in lineNumber.RUNS)
3625
            {
3626
                foreach (var item in run.RUNITEMS)
3627
                {
3628
                    if (item.GetType() == typeof(Symbol))
3629
                    {
3630
                        Symbol symbol = item as Symbol;
3631
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3632
                        if (_LMSymbol != null)
3633
                        {
3634
                            LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3635

    
3636
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3637
                            {
3638
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3639
                                {
3640
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3641
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3642
                                    {
3643
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3644
                                        if (_LMAAttribute != null)
3645
                                        {
3646
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3647
                                                _LMAAttribute.set_Value(attribute.VALUE);
3648
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3649
                                                _LMAAttribute.set_Value(attribute.VALUE);
3650
                                        }
3651
                                    }
3652
                                }
3653
                                _LMModelItem.Commit();
3654
                            }
3655
                            if (_LMModelItem != null)
3656
                                ReleaseCOMObjects(_LMModelItem);
3657
                        }
3658
                        if (_LMSymbol != null)
3659
                            ReleaseCOMObjects(_LMSymbol);
3660
                    }
3661
                    else if (item.GetType() == typeof(Line))
3662
                    {
3663
                        Line line = item as Line;
3664
                        if (line != null && !endLine.Contains(line.SPPID.ModelItemId))
3665
                        {
3666
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3667
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3668
                            {
3669
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3670
                                {
3671
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3672
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3673
                                    {
3674
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3675
                                        if (_LMAAttribute != null)
3676
                                        {
3677
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3678
                                                _LMAAttribute.set_Value(attribute.VALUE);
3679
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3680
                                                _LMAAttribute.set_Value(attribute.VALUE);
3681

    
3682
                                        }
3683
                                    }
3684
                                }
3685
                                _LMModelItem.Commit();
3686
                            }
3687
                            if (_LMModelItem != null)
3688
                                ReleaseCOMObjects(_LMModelItem);
3689
                            endLine.Add(line.SPPID.ModelItemId);
3690
                        }
3691
                    }
3692
                }
3693
            }
3694
        }
3695

    
3696
        /// <summary>
3697
        /// Symbol Attribute 입력 메서드
3698
        /// </summary>
3699
        /// <param name="item"></param>
3700
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3701
        {
3702
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3703
            string sRep = null;
3704
            if (targetItem.GetType() == typeof(Symbol))
3705
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3706
            else if (targetItem.GetType() == typeof(Equipment))
3707
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3708

    
3709
            if (!string.IsNullOrEmpty(sRep))
3710
            {
3711
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3712
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3713
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3714
                
3715
                foreach (var item in targetAttributes)
3716
                {
3717
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3718
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3719
                    {
3720
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3721
                        if (_Attribute != null)
3722
                        {
3723
                            object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
3724
                            if (associItem != null)
3725
                            {
3726
                                if (associItem.GetType() == typeof(Text))
3727
                                {
3728
                                    Text text = associItem as Text;
3729
                                    text.SPPID.RepresentationId = "Attribute";
3730
                                }
3731
                                else if (associItem.GetType() == typeof(Note))
3732
                                {
3733
                                    Note note = associItem as Note;
3734
                                    note.SPPID.RepresentationId = "Attribute";
3735
                                }
3736
                            }
3737
                            _Attribute.set_Value(item.VALUE);
3738
                            // OPC 일경우 Attribute 저장
3739
                            if (targetItem.GetType() == typeof(Symbol))
3740
                            {
3741
                                Symbol symbol = targetItem as Symbol;
3742
                                if (symbol.TYPE == "Piping OPC's" || symbol.TYPE == "Instrument OPC's")
3743
                                    symbol.SPPID.Attributes.Add(new string[] { mapping.SPPIDATTRIBUTENAME, item.VALUE });
3744
                            }
3745
                        }
3746
                    }
3747
                }
3748
                _LMModelItem.Commit();
3749

    
3750
                ReleaseCOMObjects(_Attributes);
3751
                ReleaseCOMObjects(_LMModelItem);
3752
                ReleaseCOMObjects(_LMSymbol);
3753
            }
3754
        }
3755

    
3756
        /// <summary>
3757
        /// Input SpecBreak Attribute
3758
        /// </summary>
3759
        /// <param name="specBreak"></param>
3760
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3761
        {
3762
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3763
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3764

    
3765
            if (upStreamObj != null &&
3766
                downStreamObj != null)
3767
            {
3768
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3769

    
3770
                if (targetLMConnector != null)
3771
                {
3772
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
3773
                    {
3774
                        string symbolPath = _LMLabelPersist.get_FileName();
3775
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
3776
                        if (mapping != null)
3777
                        {
3778
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
3779
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3780
                            {
3781
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
3782
                                if (values.Length == 2)
3783
                                {
3784
                                    string upStreamValue = values[0];
3785
                                    string downStreamValue = values[1];
3786

    
3787
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3788
                                }
3789
                            }
3790
                        }
3791
                    }
3792

    
3793
                    ReleaseCOMObjects(targetLMConnector);
3794
                }
3795
            }
3796

    
3797

    
3798
            #region 내부에서만 쓰는 메서드
3799
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
3800
            {
3801
                Symbol upStreamSymbol = _upStreamObj as Symbol;
3802
                Line upStreamLine = _upStreamObj as Line;
3803
                Symbol downStreamSymbol = _downStreamObj as Symbol;
3804
                Line downStreamLine = _downStreamObj as Line;
3805
                // 둘다 Line일 경우
3806
                if (upStreamLine != null && downStreamLine != null)
3807
                {
3808
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3809
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3810
                }
3811
                // 둘다 Symbol일 경우
3812
                else if (upStreamSymbol != null && downStreamSymbol != null)
3813
                {
3814
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
3815
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3816
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3817

    
3818
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3819
                    {
3820
                        if (connector.get_ItemStatus() != "Active")
3821
                            continue;
3822

    
3823
                        if (connector.Id != zeroLenthConnector.Id)
3824
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3825
                    }
3826

    
3827
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3828
                    {
3829
                        if (connector.get_ItemStatus() != "Active")
3830
                            continue;
3831

    
3832
                        if (connector.Id != zeroLenthConnector.Id)
3833
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3834
                    }
3835

    
3836
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3837
                    {
3838
                        if (connector.get_ItemStatus() != "Active")
3839
                            continue;
3840

    
3841
                        if (connector.Id != zeroLenthConnector.Id)
3842
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3843
                    }
3844

    
3845
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3846
                    {
3847
                        if (connector.get_ItemStatus() != "Active")
3848
                            continue;
3849

    
3850
                        if (connector.Id != zeroLenthConnector.Id)
3851
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3852
                    }
3853

    
3854
                    ReleaseCOMObjects(zeroLenthConnector);
3855
                    ReleaseCOMObjects(upStreamLMSymbol);
3856
                    ReleaseCOMObjects(downStreamLMSymbol);
3857
                }
3858
                else if (upStreamSymbol != null && downStreamLine != null)
3859
                {
3860
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3861
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3862
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3863

    
3864
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3865
                    {
3866
                        if (connector.get_ItemStatus() != "Active")
3867
                            continue;
3868

    
3869
                        if (connector.Id == zeroLenthConnector.Id)
3870
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3871
                    }
3872

    
3873
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3874
                    {
3875
                        if (connector.get_ItemStatus() != "Active")
3876
                            continue;
3877

    
3878
                        if (connector.Id == zeroLenthConnector.Id)
3879
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3880
                    }
3881

    
3882
                    ReleaseCOMObjects(zeroLenthConnector);
3883
                    ReleaseCOMObjects(upStreamLMSymbol);
3884
                }
3885
                else if (upStreamLine != null && downStreamSymbol != null)
3886
                {
3887
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3888
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3889
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3890

    
3891
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3892
                    {
3893
                        if (connector.get_ItemStatus() != "Active")
3894
                            continue;
3895

    
3896
                        if (connector.Id == zeroLenthConnector.Id)
3897
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3898
                    }
3899

    
3900
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3901
                    {
3902
                        if (connector.get_ItemStatus() != "Active")
3903
                            continue;
3904

    
3905
                        if (connector.Id == zeroLenthConnector.Id)
3906
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3907
                    }
3908

    
3909
                    ReleaseCOMObjects(zeroLenthConnector);
3910
                    ReleaseCOMObjects(downStreamLMSymbol);
3911
                }
3912
            }
3913

    
3914
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3915
            {
3916
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3917
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3918
                {
3919
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3920
                    if (_LMAAttribute != null)
3921
                    {
3922
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3923
                            _LMAAttribute.set_Value(value);
3924
                        else if (_LMAAttribute.get_Value() != value)
3925
                            _LMAAttribute.set_Value(value);
3926
                    }
3927

    
3928
                    _LMModelItem.Commit();
3929
                }
3930
                if (_LMModelItem != null)
3931
                    ReleaseCOMObjects(_LMModelItem);
3932
            }
3933

    
3934
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3935
            {
3936
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3937
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3938
                {
3939
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3940
                    if (_LMAAttribute != null)
3941
                    {
3942
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3943
                            _LMAAttribute.set_Value(value);
3944
                        else if (_LMAAttribute.get_Value() != value)
3945
                            _LMAAttribute.set_Value(value);
3946
                    }
3947

    
3948
                    _LMModelItem.Commit();
3949
                }
3950
                if (_LMModelItem != null)
3951
                    ReleaseCOMObjects(_LMModelItem);
3952
            }
3953
            #endregion
3954
        }
3955

    
3956
        /// <summary>
3957
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3958
        /// </summary>
3959
        /// <param name="text"></param>
3960
        private void TextModeling(Text text, List<Text> correctList)
3961
        {
3962
            LMSymbol _LMSymbol = null;
3963
            LMConnector connectedLMConnector = null;
3964
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
3965
            if (text.ASSOCIATION)
3966
            {
3967
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
3968
                if (owner != null && owner.GetType() == typeof(Symbol))
3969
                {
3970
                    Symbol symbol = owner as Symbol;
3971
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3972
                    if (_LMSymbol != null)
3973
                    {
3974
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3975
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3976
                        {
3977
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3978

    
3979
                            if (mapping != null)
3980
                            {
3981
                                double x = 0;
3982
                                double y = 0;
3983

    
3984
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3985
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
3986
                                Array array = new double[] { 0, x, y };
3987
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3988
                                if (_LMLabelPersist != null)
3989
                                {
3990
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
3991
                                    _LMLabelPersist.Commit();
3992
                                    ReleaseCOMObjects(_LMLabelPersist);
3993
                                }
3994
                            }
3995
                        }
3996
                    }
3997
                }
3998
                else if (owner != null && owner.GetType() == typeof(Line))
3999
                {
4000
                    Line line = owner as Line;
4001
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
4002
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
4003

    
4004
                    if (connectedLMConnector != null)
4005
                    {
4006
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4007
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4008
                        {
4009
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4010

    
4011
                            if (mapping != null)
4012
                            {
4013
                                double x = 0;
4014
                                double y = 0;
4015
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4016
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4017
                                Array array = new double[] { 0, x, y };
4018

    
4019
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4020
                                if (_LMLabelPersist != null)
4021
                                {
4022
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4023
                                    _LMLabelPersist.Commit();
4024
                                    ReleaseCOMObjects(_LMLabelPersist);
4025
                                }
4026
                            }
4027
                        }
4028
                    }
4029
                }
4030
            }
4031
            else
4032
            {
4033
                LMItemNote _LMItemNote = null;
4034
                LMAAttribute _LMAAttribute = null;
4035

    
4036
                double x = 0;
4037
                double y = 0;
4038
                double angle = text.ANGLE;
4039
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
4040

    
4041
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4042
                text.SPPID.SPPID_X = x;
4043
                text.SPPID.SPPID_Y = y;
4044

    
4045
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
4046
                if (_LMSymbol != null)
4047
                {
4048
                    _LMSymbol.Commit();
4049
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4050
                    if (_LMItemNote != null)
4051
                    {
4052
                        _LMItemNote.Commit();
4053
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4054
                        if (_LMAAttribute != null)
4055
                        {
4056
                            _LMAAttribute.set_Value(text.VALUE);
4057
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4058
                            _LMItemNote.Commit();
4059

    
4060

    
4061
                            double[] range = null;
4062
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4063
                            {
4064
                                double[] temp = null;
4065
                                GetSPPIDSymbolRange(labelPersist, ref temp);
4066
                                if (temp != null)
4067
                                {
4068
                                    if (range == null)
4069
                                        range = temp;
4070
                                    else
4071
                                    {
4072
                                        range = new double[] {
4073
                                            Math.Min(range[0], temp[0]),
4074
                                            Math.Min(range[1], temp[1]),
4075
                                            Math.Max(range[2], temp[2]),
4076
                                            Math.Max(range[3], temp[3])
4077
                                        };
4078
                                    }
4079
                                }
4080
                            }
4081
                            if (range != null)
4082
                                correctList.Add(text);
4083
                            text.SPPID.Range = range;
4084

    
4085

    
4086
                            if (_LMAAttribute != null)
4087
                                ReleaseCOMObjects(_LMAAttribute);
4088
                            if (_LMItemNote != null)
4089
                                ReleaseCOMObjects(_LMItemNote);
4090
                        }
4091
                    }
4092
                }
4093
            }
4094
            if (_LMSymbol != null)
4095
                ReleaseCOMObjects(_LMSymbol);
4096
        }
4097

    
4098
        private void TextCorrectModeling(Text text, List<Text> endList)
4099
        {
4100
            bool needRemodeling = false;
4101
            bool loop = true;
4102
            GridSetting gridSetting = GridSetting.GetInstance();
4103
            while (loop)
4104
            {
4105
                loop = false;
4106
                foreach (var overlapText in endList)
4107
                {
4108
                    if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range))
4109
                    {
4110
                        double tempX = 0;
4111
                        double tempY = 0;
4112
                        bool overlapX = false;
4113
                        bool overlapY = false;
4114
                        SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
4115
                        double angle = SPPIDUtil.CalcAngle(text.LOCATION_X, text.LOCATION_Y, overlapText.LOCATION_X, overlapText.LOCATION_Y);
4116
                        if (overlapY && angle >= 45)
4117
                        {
4118
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
4119
                            double move = gridSetting.Length * count;
4120
                            text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move;
4121
                            text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move };
4122
                            needRemodeling = true;
4123
                            loop = true;
4124
                        }
4125
                        if (overlapX && angle <= 45)
4126
                        {
4127
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
4128
                            double move = gridSetting.Length * count;
4129
                            text.SPPID.SPPID_X = text.SPPID.SPPID_X + move;
4130
                            text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] };
4131
                            needRemodeling = true;
4132
                            loop = true;
4133
                        }
4134
                    }
4135
                }
4136
            }
4137
            
4138

    
4139
            if (needRemodeling)
4140
            {
4141
                LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId);
4142
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
4143
                text.SPPID.RepresentationId = null;
4144

    
4145
                LMItemNote _LMItemNote = null;
4146
                LMAAttribute _LMAAttribute = null;
4147
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE);
4148
                if (_LMSymbol != null)
4149
                {
4150
                    _LMSymbol.Commit();
4151
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4152
                    if (_LMItemNote != null)
4153
                    {
4154
                        _LMItemNote.Commit();
4155
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4156
                        if (_LMAAttribute != null)
4157
                        {
4158
                            _LMAAttribute.set_Value(text.VALUE);
4159
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4160
                            _LMItemNote.Commit();
4161

    
4162
                            ReleaseCOMObjects(_LMAAttribute);
4163
                            ReleaseCOMObjects(_LMItemNote);
4164
                        }
4165
                    }
4166
                }
4167

    
4168
                ReleaseCOMObjects(symbol);
4169
                symbol = null;
4170
                ReleaseCOMObjects(_LMItemNote);
4171
                _LMItemNote = null;
4172
                ReleaseCOMObjects(_LMAAttribute);
4173
                _LMAAttribute = null;
4174
                ReleaseCOMObjects(_LMSymbol);
4175
                _LMSymbol = null;
4176
            }
4177

    
4178
            endList.Add(text);
4179
        }
4180

    
4181
        /// <summary>
4182
        /// Note Modeling
4183
        /// </summary>
4184
        /// <param name="note"></param>
4185
        private void NoteModeling(Note note, List<Note> correctList)
4186
        {
4187
            LMSymbol _LMSymbol = null;
4188
            LMItemNote _LMItemNote = null;
4189
            LMAAttribute _LMAAttribute = null;
4190

    
4191
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
4192
            {
4193
                double x = 0;
4194
                double y = 0;
4195

    
4196
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
4197
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
4198
                note.SPPID.SPPID_X = x;
4199
                note.SPPID.SPPID_Y = y;
4200

    
4201
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
4202
                if (_LMSymbol != null)
4203
                {
4204
                    _LMSymbol.Commit();
4205
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4206
                    if (_LMItemNote != null)
4207
                    {
4208
                        _LMItemNote.Commit();
4209
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4210
                        if (_LMAAttribute != null)
4211
                        {
4212
                            _LMAAttribute.set_Value(note.VALUE);
4213
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4214

    
4215
                            double[] range = null;
4216
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4217
                            {
4218
                                double[] temp = null;
4219
                                GetSPPIDSymbolRange(labelPersist, ref temp);
4220
                                if (temp != null)
4221
                                {
4222
                                    if (range == null)
4223
                                        range = temp;
4224
                                    else
4225
                                    {
4226
                                        range = new double[] {
4227
                                            Math.Min(range[0], temp[0]),
4228
                                            Math.Min(range[1], temp[1]),
4229
                                            Math.Max(range[2], temp[2]),
4230
                                            Math.Max(range[3], temp[3])
4231
                                        };
4232
                                    }
4233
                                }
4234
                            }
4235
                            if (range != null)
4236
                                correctList.Add(note);
4237
                            note.SPPID.Range = range;
4238

    
4239

    
4240
                            _LMItemNote.Commit();
4241
                        }
4242
                    }
4243
                }
4244
            }
4245

    
4246
            if (_LMAAttribute != null)
4247
                ReleaseCOMObjects(_LMAAttribute);
4248
            if (_LMItemNote != null)
4249
                ReleaseCOMObjects(_LMItemNote);
4250
            if (_LMSymbol != null)
4251
                ReleaseCOMObjects(_LMSymbol);
4252
        }
4253

    
4254
        private void NoteCorrectModeling(Note note, List<Note> endList)
4255
        {
4256
            bool needRemodeling = false;
4257
            bool loop = true;
4258
            GridSetting gridSetting = GridSetting.GetInstance();
4259
            while (loop)
4260
            {
4261
                loop = false;
4262
                foreach (var overlap in endList)
4263
                {
4264
                    if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range))
4265
                    {
4266
                        double tempX = 0;
4267
                        double tempY = 0;
4268
                        bool overlapX = false;
4269
                        bool overlapY = false;
4270
                        SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
4271
                        double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y);
4272
                        if (overlapY && angle >= 45)
4273
                        {
4274
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
4275
                            double move = gridSetting.Length * count;
4276
                            note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move;
4277
                            note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move };
4278
                            needRemodeling = true;
4279
                            loop = true;
4280
                        }
4281
                        if (overlapX && angle <= 45)
4282
                        {
4283
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
4284
                            double move = gridSetting.Length * count;
4285
                            note.SPPID.SPPID_X = note.SPPID.SPPID_X + move;
4286
                            note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] };
4287
                            needRemodeling = true;
4288
                            loop = true;
4289
                        }
4290
                    }
4291
                }
4292
            }
4293

    
4294

    
4295
            if (needRemodeling)
4296
            {
4297
                LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId);
4298
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
4299
                note.SPPID.RepresentationId = null;
4300

    
4301
                LMItemNote _LMItemNote = null;
4302
                LMAAttribute _LMAAttribute = null;
4303
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE);
4304
                if (_LMSymbol != null)
4305
                {
4306
                    _LMSymbol.Commit();
4307
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4308
                    if (_LMItemNote != null)
4309
                    {
4310
                        _LMItemNote.Commit();
4311
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4312
                        if (_LMAAttribute != null)
4313
                        {
4314
                            _LMAAttribute.set_Value(note.VALUE);
4315
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4316
                            _LMItemNote.Commit();
4317

    
4318
                            ReleaseCOMObjects(_LMAAttribute);
4319
                            ReleaseCOMObjects(_LMItemNote);
4320
                        }
4321
                    }
4322
                }
4323

    
4324
                ReleaseCOMObjects(symbol);
4325
                symbol = null;
4326
                ReleaseCOMObjects(_LMItemNote);
4327
                _LMItemNote = null;
4328
                ReleaseCOMObjects(_LMAAttribute);
4329
                _LMAAttribute = null;
4330
                ReleaseCOMObjects(_LMSymbol);
4331
                _LMSymbol = null;
4332
            }
4333

    
4334
            endList.Add(note);
4335
        }
4336

    
4337
        private void JoinRunBySameType(string modelItemId, ref string survivorId)
4338
        {
4339
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
4340
            if (modelItem != null)
4341
            {
4342
                foreach (LMRepresentation rep in modelItem.Representations)
4343
                {
4344
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
4345
                    {
4346
                        LMConnector connector = dataSource.GetConnector(rep.Id);
4347
                        if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
4348
                        {
4349
                            LMSymbol symbol = connector.ConnectItem1SymbolObject;
4350
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
4351
                            if (modelItemIds.Count == 1)
4352
                            {
4353
                                string joinModelItemId = modelItemIds[0];
4354
                                JoinRun(joinModelItemId, modelItemId, ref survivorId);
4355
                                if (survivorId != null)
4356
                                    break;
4357
                            }
4358
                        }
4359
                        if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
4360
                        {
4361
                            LMSymbol symbol = connector.ConnectItem2SymbolObject;
4362
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
4363
                            if (modelItemIds.Count == 1)
4364
                            {
4365
                                string joinModelItemId = modelItemIds[0];
4366
                                JoinRun(joinModelItemId, modelItemId, ref survivorId);
4367
                                if (survivorId != null)
4368
                                    break;
4369
                            }
4370
                        }
4371
                    }
4372
                }
4373
            }
4374
        }
4375

    
4376
        /// <summary>
4377
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
4378
        /// </summary>
4379
        /// <param name="x"></param>
4380
        /// <param name="y"></param>
4381
        /// <param name="originX"></param>
4382
        /// <param name="originY"></param>
4383
        /// <param name="SPPIDLabelLocation"></param>
4384
        /// <param name="location"></param>
4385
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
4386
        {
4387
            if (location == Location.None)
4388
            {
4389
                x = originX;
4390
                y = originY;
4391
            }
4392
            else
4393
            {
4394
                if (location.HasFlag(Location.Center))
4395
                {
4396
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
4397
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
4398
                }
4399

    
4400
                if (location.HasFlag(Location.Left))
4401
                    x = SPPIDLabelLocation.X1;
4402
                else if (location.HasFlag(Location.Right))
4403
                    x = SPPIDLabelLocation.X2;
4404

    
4405
                if (location.HasFlag(Location.Down))
4406
                    y = SPPIDLabelLocation.Y1;
4407
                else if (location.HasFlag(Location.Up))
4408
                    y = SPPIDLabelLocation.Y2;
4409
            }
4410
        }
4411

    
4412
        /// <summary>
4413
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
4414
        /// 1. Angle Valve
4415
        /// 2. 3개로 이루어진 Symbol Group
4416
        /// </summary>
4417
        /// <returns></returns>
4418
        private List<Symbol> GetPrioritySymbol()
4419
        {
4420
            DataTable symbolTable = document.SymbolTable;
4421
            // List에 순서대로 쌓는다.
4422
            List<Symbol> symbols = new List<Symbol>();
4423

    
4424
            // Angle Valve 부터
4425
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
4426
            {
4427
                if (!symbols.Contains(symbol))
4428
                {
4429
                    double originX = 0;
4430
                    double originY = 0;
4431

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

    
4436
                    SlopeType slopeType1 = SlopeType.None;
4437
                    SlopeType slopeType2 = SlopeType.None;
4438
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
4439
                    {
4440
                        double connectorX = 0;
4441
                        double connectorY = 0;
4442
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
4443
                        if (slopeType1 == SlopeType.None)
4444
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
4445
                        else
4446
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
4447
                    }
4448

    
4449
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
4450
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
4451
                        symbols.Add(symbol);
4452
                }
4453
            }
4454

    
4455
            List<Symbol> tempSymbols = new List<Symbol>();
4456
            // Conn 갯수 기준
4457
            foreach (var item in document.SYMBOLS)
4458
            {
4459
                if (!symbols.Contains(item))
4460
                    tempSymbols.Add(item);
4461
            }
4462
            tempSymbols.Sort(SortSymbolPriority);
4463
            symbols.AddRange(tempSymbols);
4464

    
4465
            return symbols;
4466
        }
4467

    
4468
        private void SetPriorityLine(List<Line> lines)
4469
        {
4470
            lines.Sort(SortLinePriority);
4471

    
4472
            int SortLinePriority(Line a, Line b)
4473
            {
4474
                // Branch 없는것부터
4475
                int branchRetval = CompareBranchLine(a, b);
4476
                if (branchRetval != 0)
4477
                {
4478
                    return branchRetval;
4479
                }
4480
                else
4481
                {
4482
                    // Symbol 연결 갯수
4483
                    int connSymbolRetval = CompareConnSymbol(a, b);
4484
                    if (connSymbolRetval != 0)
4485
                    {
4486
                        return connSymbolRetval;
4487
                    }
4488
                    else
4489
                    {
4490
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
4491
                        int connItemRetval = CompareConnItem(a, b);
4492
                        if (connItemRetval != 0)
4493
                        {
4494
                            return connItemRetval;
4495
                        }
4496
                        else
4497
                        {
4498
                            // ConnectedItem이 없는것
4499
                            int noneConnRetval = CompareNoneConn(a, b);
4500
                            if (noneConnRetval != 0)
4501
                            {
4502
                                return noneConnRetval;
4503
                            }
4504
                            else
4505
                            {
4506

    
4507
                            }
4508
                        }
4509
                    }
4510
                }
4511

    
4512
                return 0;
4513
            }
4514

    
4515
            int CompareNotSegmentLine(Line a, Line b)
4516
            {
4517
                List<Connector> connectorsA = a.CONNECTORS
4518
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
4519
                    .ToList();
4520

    
4521
                List<Connector> connectorsB = b.CONNECTORS
4522
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
4523
                    .ToList();
4524

    
4525
                // 오름차순
4526
                return connectorsB.Count.CompareTo(connectorsA.Count);
4527
            }
4528

    
4529
            int CompareConnSymbol(Line a, Line b)
4530
            {
4531
                List<Connector> connectorsA = a.CONNECTORS
4532
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
4533
                    .ToList();
4534

    
4535
                List<Connector> connectorsB = b.CONNECTORS
4536
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
4537
                    .ToList();
4538

    
4539
                // 오름차순
4540
                return connectorsB.Count.CompareTo(connectorsA.Count);
4541
            }
4542

    
4543
            int CompareConnItem(Line a, Line b)
4544
            {
4545
                List<Connector> connectorsA = a.CONNECTORS
4546
                    .Where(conn => conn.ConnectedObject != null && 
4547
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
4548
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
4549
                    .ToList();
4550

    
4551
                List<Connector> connectorsB = b.CONNECTORS
4552
                    .Where(conn => conn.ConnectedObject != null &&
4553
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
4554
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
4555
                    .ToList();
4556

    
4557
                // 오름차순
4558
                return connectorsB.Count.CompareTo(connectorsA.Count);
4559
            }
4560

    
4561
            int CompareBranchLine(Line a, Line b)
4562
            {
4563
                List<Connector> connectorsA = a.CONNECTORS
4564
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
4565
                    .ToList();
4566
                List<Connector> connectorsB = b.CONNECTORS
4567
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
4568
                    .ToList();
4569

    
4570
                // 내림차순
4571
                return connectorsA.Count.CompareTo(connectorsB.Count);
4572
            }
4573

    
4574
            int CompareNoneConn(Line a, Line b)
4575
            {
4576
                List<Connector> connectorsA = a.CONNECTORS
4577
                    .Where(conn => conn.ConnectedObject == null)
4578
                    .ToList();
4579

    
4580
                List<Connector> connectorsB = b.CONNECTORS
4581
                    .Where(conn => conn.ConnectedObject == null)
4582
                    .ToList();
4583

    
4584
                // 오름차순
4585
                return connectorsB.Count.CompareTo(connectorsA.Count);
4586
            }
4587
        }
4588

    
4589
        private void SortText(List<Text> texts)
4590
        {
4591
            texts.Sort(Sort);
4592

    
4593
            int Sort(Text a, Text b)
4594
            {
4595
                int yRetval = CompareY(a, b);
4596
                if (yRetval != 0)
4597
                {
4598
                    return yRetval;
4599
                }
4600
                else
4601
                {
4602
                    return CompareX(a, b);
4603
                }
4604
            }
4605

    
4606
            int CompareY(Text a, Text b)
4607
            {
4608
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
4609
            }
4610

    
4611
            int CompareX(Text a, Text b)
4612
            {
4613
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
4614
            }
4615
        }
4616
        private void SortNote(List<Note> notes)
4617
        {
4618
            notes.Sort(Sort);
4619

    
4620
            int Sort(Note a, Note b)
4621
            {
4622
                int yRetval = CompareY(a, b);
4623
                if (yRetval != 0)
4624
                {
4625
                    return yRetval;
4626
                }
4627
                else
4628
                {
4629
                    return CompareX(a, b);
4630
                }
4631
            }
4632

    
4633
            int CompareY(Note a, Note b)
4634
            {
4635
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
4636
            }
4637

    
4638
            int CompareX(Note a, Note b)
4639
            {
4640
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
4641
            }
4642
        }
4643

    
4644
        private void SortBranchLines()
4645
        {
4646
            BranchLines.Sort(SortBranchLine);
4647
            int SortBranchLine(Line a, Line b)
4648
            {
4649
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
4650
                 x.ConnectedObject.GetType() == typeof(Line) &&
4651
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
4652
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
4653

    
4654
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
4655
                 x.ConnectedObject.GetType() == typeof(Line) &&
4656
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
4657
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
4658

    
4659
                // 내림차순
4660
                return countA.CompareTo(countB);
4661
            }
4662
        }
4663

    
4664
        private static int SortSymbolPriority(Symbol a, Symbol b)
4665
        {
4666
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
4667
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
4668
            int retval = countB.CompareTo(countA);
4669
            if (retval != 0)
4670
                return retval;
4671
            else
4672
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
4673
        }
4674

    
4675
        private string GetSPPIDFileName(LMModelItem modelItem)
4676
        {
4677
            string symbolPath = null;
4678
            foreach (LMRepresentation rep in modelItem.Representations)
4679
            {
4680
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
4681
                {
4682
                    symbolPath = rep.get_FileName();
4683
                    break;
4684
                }
4685
            }
4686
            return symbolPath;
4687
        }
4688

    
4689
        private string GetSPPIDFileName(string modelItemId)
4690
        {
4691
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
4692
            string symbolPath = null;
4693
            foreach (LMRepresentation rep in modelItem.Representations)
4694
            {
4695
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
4696
                {
4697
                    symbolPath = rep.get_FileName();
4698
                    break;
4699
                }
4700
            }
4701
            ReleaseCOMObjects(modelItem);
4702
            return symbolPath;
4703
        }
4704

    
4705
        /// <summary>
4706
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
4707
        /// </summary>
4708
        /// <param name="graphicOID"></param>
4709
        /// <param name="milliseconds"></param>
4710
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
4711
        {
4712
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
4713
            {
4714
                double minX = 0;
4715
                double minY = 0;
4716
                double maxX = 0;
4717
                double maxY = 0;
4718
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
4719
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
4720

    
4721
                Thread.Sleep(milliseconds);
4722
            }
4723
        }
4724

    
4725
        /// <summary>
4726
        /// ComObject를 Release
4727
        /// </summary>
4728
        /// <param name="objVars"></param>
4729
        public void ReleaseCOMObjects(params object[] objVars)
4730
        {
4731
            if (objVars != null)
4732
            {
4733
                int intNewRefCount = 0;
4734
                foreach (object obj in objVars)
4735
                {
4736
                    if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
4737
                        intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
4738
                }
4739
            }
4740
        }
4741

    
4742
        /// IDisposable 구현
4743
        ~AutoModeling()
4744
        {
4745
            this.Dispose(false);
4746
        }
4747

    
4748
        private bool disposed;
4749
        public void Dispose()
4750
        {
4751
            this.Dispose(true);
4752
            GC.SuppressFinalize(this);
4753
        }
4754

    
4755
        protected virtual void Dispose(bool disposing)
4756
        {
4757
            if (this.disposed) return;
4758
            if (disposing)
4759
            {
4760
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
4761
            }
4762
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
4763
            this.disposed = true;
4764
        }
4765
    }
4766
}
클립보드 이미지 추가 (최대 크기: 500 MB)