프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 9bcb092b

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

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