프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 404185fc

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